本文整理匯總了Java中org.w3c.dom.Node.DOCUMENT_NODE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Node.DOCUMENT_NODE屬性的具體用法?Java Node.DOCUMENT_NODE怎麽用?Java Node.DOCUMENT_NODE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.DOCUMENT_NODE屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: hasLegalRootContainer
/**
* Finds the root container for the given node and determines
* if that root container is legal with respect to the
* DOM 2 specification. At present, that means the root
* container must be either an attribute, a document,
* or a document fragment.
*/
private boolean hasLegalRootContainer( Node node )
{
if ( node==null )
return false;
Node rootContainer = getRootContainer( node );
switch( rootContainer.getNodeType() )
{
case Node.ATTRIBUTE_NODE:
case Node.DOCUMENT_NODE:
case Node.DOCUMENT_FRAGMENT_NODE:
return true;
}
return false;
}
示例2: serialize
/**
* Serialize a {@link Node}.
*
* @param n the node to serialize.
*/
public final void serialize(Node n) throws IOException {
switch (n.getNodeType()) {
case Node.DOCUMENT_NODE:
serialize((Document)n);
break;
case Node.ELEMENT_NODE:
serializeElementAsDocument(n);
break;
case Node.COMMENT_NODE:
serializeComment(n);
break;
case Node.PROCESSING_INSTRUCTION_NODE:
serializeProcessingInstruction(n);
break;
}
}
示例3: nodeToString
private static String nodeToString(Node node) {
int nodeType = node.getNodeType();
switch (nodeType) {
case Node.DOCUMENT_NODE:
return XMLUtils.prettyPrintElement(((Document) node).getDocumentElement(), true, false);
case Node.ELEMENT_NODE:
return XMLUtils.prettyPrintElement((Element) node, true, false);
case Node.CDATA_SECTION_NODE:
case Node.TEXT_NODE:
int len = node.getChildNodes().getLength();
return ((len<2) ? node.getNodeValue():XMLUtils.getNormalizedText(node));
case Node.ATTRIBUTE_NODE:
return node.getNodeValue();
default:
return null;
}
}
示例4: writeTo
public void writeTo(SOAPMessage saaj) throws SOAPException {
try {
// TODO what about in-scope namespaces
// Not very efficient consider implementing a stream buffer
// processor that produces a DOM node from the buffer.
TransformerFactory tf = XmlUtil.newTransformerFactory(true);
Transformer t = tf.newTransformer();
XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
DOMResult result = new DOMResult();
t.transform(source, result);
Node d = result.getNode();
if(d.getNodeType() == Node.DOCUMENT_NODE)
d = d.getFirstChild();
SOAPHeader header = saaj.getSOAPHeader();
if(header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
Node node = header.getOwnerDocument().importNode(d, true);
header.appendChild(node);
} catch (Exception e) {
throw new SOAPException(e);
}
}
示例5: _getXmlEncoding
private String _getXmlEncoding(Node node) {
Document doc = (node.getNodeType() == Node.DOCUMENT_NODE)
? (Document) node : node.getOwnerDocument();
if (doc != null) {
try {
return doc.getXmlEncoding();
} // The VM ran out of memory or there was some other serious problem. Re-throw.
catch (VirtualMachineError | ThreadDeath vme) {
throw vme;
} // Ignore all other exceptions and errors
catch (Throwable t) {
}
}
return null;
}
示例6: write
public static void write(IEnumerable what, Node where) throws Exception
{
Document owner = (where.getNodeType() == Node.DOCUMENT_NODE) ? (Document) where : where.getOwnerDocument();
for (IEnumerator en = what.enumerator(); en.moveNext();)
{
if (en.current() instanceof IMFNode)
{
IMFNode el = (IMFNode)en.current();
if ((el.getNodeKind() & IMFNode.MFNodeKind_Element) != 0)
{
Element xel = appendElement(owner, where, el.getNamespaceURI(), el.getLocalName(), el.getPrefix());
write(el.select(IMFNode.MFQueryKind_All, null), xel);
}
if ((el.getNodeKind() & IMFNode.MFNodeKind_Attribute) != 0)
{
appendAttribute(owner, where, el.getNamespaceURI(), el.getLocalName(), el.getPrefix(), getValue(el, where));
}
else if ((el.getNodeKind() & IMFNode.MFNodeKind_Comment) != 0)
{
where.appendChild(owner.createComment(getValue(el,where)));
}
else if ((el.getNodeKind() & IMFNode.MFNodeKind_ProcessingInstruction) != 0)
{
where.appendChild(owner.createProcessingInstruction(el.getLocalName(), getValue(el,where)));
}
else if ((el.getNodeKind() & IMFNode.MFNodeKind_CData) != 0)
{
where.appendChild(owner.createCDATASection(getValue(el,where)));
}
else if ((el.getNodeKind() & IMFNode.MFNodeKind_Text) != 0)
{
where.appendChild(owner.createTextNode(getValue(el,where)));
}
}
else
{
where.appendChild(owner.createTextNode(getValue(en.current(), where)));
}
}
}
示例7: getNodeData
/**
* Retrieve the text content of a DOM subtree, appending it into a
* user-supplied FastStringBuffer object. Note that attributes are
* not considered part of the content of an element.
* <p>
* There are open questions regarding whitespace stripping.
* Currently we make no special effort in that regard, since the standard
* DOM doesn't yet provide DTD-based information to distinguish
* whitespace-in-element-context from genuine #PCDATA. Note that we
* should probably also consider xml:space if/when we address this.
* DOM Level 3 may solve the problem for us.
*
* @param node Node whose subtree is to be walked, gathering the
* contents of all Text or CDATASection nodes.
* @param buf FastStringBuffer into which the contents of the text
* nodes are to be concatenated.
*/
public static void getNodeData(Node node, FastStringBuffer buf)
{
switch (node.getNodeType())
{
case Node.DOCUMENT_FRAGMENT_NODE :
case Node.DOCUMENT_NODE :
case Node.ELEMENT_NODE :
{
for (Node child = node.getFirstChild(); null != child;
child = child.getNextSibling())
{
getNodeData(child, buf);
}
}
break;
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE :
buf.append(node.getNodeValue());
break;
case Node.ATTRIBUTE_NODE :
buf.append(node.getNodeValue());
break;
case Node.PROCESSING_INSTRUCTION_NODE :
// warning(XPATHErrorResources.WG_PARSING_AND_PREPARING);
break;
default :
// ignore
break;
}
}
示例8: getMessage
public Message getMessage(MessageHeaders headers, AttachmentSet attachments, WSBinding binding) {
Node n = dom.getNode();
if(n.getNodeType()== Node.DOCUMENT_NODE) {
n = ((Document)n).getDocumentElement();
}
return new DOMMessage(binding.getSOAPVersion(), headers, (Element)n, attachments);
}
示例9: useIsSameNode
/**
* Use isSameNode() for testing node identity if the DOM implementation
* supports DOM Level 3 core and it isn't the Xerces implementation.
*/
private boolean useIsSameNode(Node node) {
if (node instanceof NodeImpl) {
return false;
}
Document doc = node.getNodeType() == Node.DOCUMENT_NODE
? (Document) node : node.getOwnerDocument();
return (doc != null && doc.getImplementation().hasFeature("Core", "3.0"));
}
示例10: eval
/**
* Evaluate XPath string to an XObject.
* XPath namespace prefixes are resolved from the namespaceNode.
* The implementation of this is a little slow, since it creates
* a number of objects each time it is called. This could be optimized
* to keep the same objects around, but then thread-safety issues would arise.
*
* @param contextNode The node to start searching from.
* @param str A valid XPath string.
* @param namespaceNode The node from which prefixes in the XPath will be resolved to namespaces.
* @return An XObject, which can be used to obtain a string, number, nodelist, etc, should never be null.
* @see com.sun.org.apache.xpath.internal.objects.XObject
* @see com.sun.org.apache.xpath.internal.objects.XNull
* @see com.sun.org.apache.xpath.internal.objects.XBoolean
* @see com.sun.org.apache.xpath.internal.objects.XNumber
* @see com.sun.org.apache.xpath.internal.objects.XString
* @see com.sun.org.apache.xpath.internal.objects.XRTreeFrag
*
* @throws TransformerException
*/
public static XObject eval(Node contextNode, String str, Node namespaceNode)
throws TransformerException
{
// Since we don't have a XML Parser involved here, install some default support
// for things like namespaces, etc.
// (Changed from: XPathContext xpathSupport = new XPathContext();
// because XPathContext is weak in a number of areas... perhaps
// XPathContext should be done away with.)
XPathContext xpathSupport = new XPathContext();
// Create an object to resolve namespace prefixes.
// XPath namespaces are resolved from the input context node's document element
// if it is a root node, or else the current context node (for lack of a better
// resolution space, given the simplicity of this sample code).
PrefixResolverDefault prefixResolver = new PrefixResolverDefault(
(namespaceNode.getNodeType() == Node.DOCUMENT_NODE)
? ((Document) namespaceNode).getDocumentElement() : namespaceNode);
// Create the XPath object.
XPath xpath = new XPath(str, null, prefixResolver, XPath.SELECT, null);
// Execute the XPath, and have it return the result
// return xpath.execute(xpathSupport, contextNode, prefixResolver);
int ctxtNode = xpathSupport.getDTMHandleFromNode(contextNode);
return xpath.execute(xpathSupport, ctxtNode, prefixResolver);
}
示例11: nodeSetMinusCommentNodes
/**
* Recursively traverses the subtree, and returns an XPath-equivalent
* node-set of all nodes traversed, excluding any comment nodes,
* if specified.
*
* @param node the node to traverse
* @param nodeSet the set of nodes traversed so far
* @param the previous sibling node
*/
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
Node prevSibling)
{
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
for (int i = 0, len = attrs.getLength(); i < len; i++) {
nodeSet.add(attrs.item(i));
}
}
nodeSet.add(node);
Node pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.DOCUMENT_NODE :
pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE:
// emulate XPath which only returns the first node in
// contiguous text/cdata nodes
if (prevSibling != null &&
(prevSibling.getNodeType() == Node.TEXT_NODE ||
prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
return;
}
nodeSet.add(node);
break;
case Node.PROCESSING_INSTRUCTION_NODE :
nodeSet.add(node);
break;
case Node.COMMENT_NODE:
if (withComments) {
nodeSet.add(node);
}
}
}
示例12: isOutsideDocElem
/**
* Tell if the current node is outside the document element.
*
* @return true if the current node is outside the document element.
*/
private boolean isOutsideDocElem() {
return (null == m_docFrag)
&& m_elemStack.size() == 0
&& (null == m_currentNode || m_currentNode.getNodeType() == Node.DOCUMENT_NODE);
}
示例13: circumventBug2650internal
/**
* This is the work horse for {@link #circumventBug2650}.
*
* @param node
* @see <A HREF="http://nagoya.apache.org/bugzilla/show_bug.cgi?id=2650">
* Namespace axis resolution is not XPath compliant </A>
*/
@SuppressWarnings("fallthrough")
private static void circumventBug2650internal(Node node) {
Node parent = null;
Node sibling = null;
final String namespaceNs = Constants.NamespaceSpecNS;
do {
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
Element element = (Element) node;
if (!element.hasChildNodes()) {
break;
}
if (element.hasAttributes()) {
NamedNodeMap attributes = element.getAttributes();
int attributesLength = attributes.getLength();
for (Node child = element.getFirstChild(); child!=null;
child = child.getNextSibling()) {
if (child.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element childElement = (Element) child;
for (int i = 0; i < attributesLength; i++) {
Attr currentAttr = (Attr) attributes.item(i);
if (!namespaceNs.equals(currentAttr.getNamespaceURI())) {
continue;
}
if (childElement.hasAttributeNS(namespaceNs,
currentAttr.getLocalName())) {
continue;
}
childElement.setAttributeNS(namespaceNs,
currentAttr.getName(),
currentAttr.getNodeValue());
}
}
}
case Node.ENTITY_REFERENCE_NODE :
case Node.DOCUMENT_NODE :
parent = node;
sibling = node.getFirstChild();
break;
}
while ((sibling == null) && (parent != null)) {
sibling = parent.getNextSibling();
parent = parent.getParentNode();
}
if (sibling == null) {
return;
}
node = sibling;
sibling = node.getNextSibling();
} while (true);
}
示例14: prepareForSerialization
private void prepareForSerialization(XMLSerializer ser, Node node) {
ser.reset();
ser.features = features;
ser.fDOMErrorHandler = fErrorHandler;
ser.fNamespaces = (features & NAMESPACES) != 0;
ser.fNamespacePrefixes = (features & NSDECL) != 0;
ser._format.setOmitComments((features & COMMENTS)==0);
ser._format.setOmitXMLDeclaration((features & XMLDECL) == 0);
ser._format.setIndenting((features & FORMAT_PRETTY_PRINT) != 0);
if ((features & WELLFORMED) != 0) {
// REVISIT: this is inefficient implementation of well-formness. Instead, we should check
// well-formness as we serialize the tree
Node next, root;
root = node;
Method versionChanged;
boolean verifyNames = true;
Document document =(node.getNodeType() == Node.DOCUMENT_NODE)
? (Document) node
: node.getOwnerDocument();
try {
versionChanged = document.getClass().getMethod("isXMLVersionChanged()", new Class[] {});
if (versionChanged != null) {
verifyNames = ((Boolean)versionChanged.invoke(document, (Object[]) null)).booleanValue();
}
} catch (Exception e) {
//no way to test the version...
//ignore the exception
}
if (node.getFirstChild() != null) {
while (node != null) {
verify(node, verifyNames, false);
// Move down to first child
next = node.getFirstChild();
// No child nodes, so walk tree
while (next == null) {
// Move to sibling if possible.
next = node.getNextSibling();
if (next == null) {
node = node.getParentNode();
if (root == node){
next = null;
break;
}
next = node.getNextSibling();
}
}
node = next;
}
}
else {
verify(node, verifyNames, false);
}
}
}
示例15: nodeSetMinusCommentNodes
/**
* Recursively traverses the subtree, and returns an XPath-equivalent
* node-set of all nodes traversed, excluding any comment nodes,
* if specified.
*
* @param node the node to traverse
* @param nodeSet the set of nodes traversed so far
* @param the previous sibling node
*/
@SuppressWarnings("fallthrough")
private void nodeSetMinusCommentNodes(Node node, List<Node> nodeSet,
Node prevSibling)
{
switch (node.getNodeType()) {
case Node.ELEMENT_NODE :
nodeSet.add(node);
NamedNodeMap attrs = node.getAttributes();
if (attrs != null) {
for (int i = 0, len = attrs.getLength(); i < len; i++) {
nodeSet.add(attrs.item(i));
}
}
Node pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.DOCUMENT_NODE :
pSibling = null;
for (Node child = node.getFirstChild(); child != null;
child = child.getNextSibling()) {
nodeSetMinusCommentNodes(child, nodeSet, pSibling);
pSibling = child;
}
break;
case Node.TEXT_NODE :
case Node.CDATA_SECTION_NODE:
// emulate XPath which only returns the first node in
// contiguous text/cdata nodes
if (prevSibling != null &&
(prevSibling.getNodeType() == Node.TEXT_NODE ||
prevSibling.getNodeType() == Node.CDATA_SECTION_NODE)) {
return;
}
nodeSet.add(node);
break;
case Node.PROCESSING_INSTRUCTION_NODE :
nodeSet.add(node);
break;
case Node.COMMENT_NODE:
if (withComments) {
nodeSet.add(node);
}
}
}