Java Code Examples for org.w3c.dom.Node#PROCESSING_INSTRUCTION_NODE
The following examples show how to use
org.w3c.dom.Node#PROCESSING_INSTRUCTION_NODE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DOMDocumentSerializer.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example 2
Source File: DOMDocumentSerializer.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * 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; } }
Example 3
Source File: XMLUtils.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Method getStrFromNode * * @param xpathnode * @return the string for the node. */ public static String getStrFromNode(Node xpathnode) { if (xpathnode.getNodeType() == Node.TEXT_NODE) { // we iterate over all siblings of the context node because eventually, // the text is "polluted" with pi's or comments StringBuilder sb = new StringBuilder(); for (Node currentSibling = xpathnode.getParentNode().getFirstChild(); currentSibling != null; currentSibling = currentSibling.getNextSibling()) { if (currentSibling.getNodeType() == Node.TEXT_NODE) { sb.append(((Text) currentSibling).getData()); } } return sb.toString(); } else if (xpathnode.getNodeType() == Node.ATTRIBUTE_NODE) { return ((Attr) xpathnode).getNodeValue(); } else if (xpathnode.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) { return ((ProcessingInstruction) xpathnode).getNodeValue(); } return null; }
Example 4
Source File: XMLEventStreamReaderTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void readCorrect() throws Exception { Transformer transformer = TransformerFactory.newInstance().newTransformer(); StAXSource source = new StAXSource(streamReader); StringWriter writer = new StringWriter(); transformer.transform(source, new StreamResult(writer)); Predicate<Node> nodeFilter = n -> n.getNodeType() != Node.DOCUMENT_TYPE_NODE && n.getNodeType() != Node.PROCESSING_INSTRUCTION_NODE; assertThat(writer.toString(), isSimilarTo(XML).withNodeFilter(nodeFilter)); }
Example 5
Source File: AbstractNodeTester.java From xmlunit with Apache License 2.0 | 5 votes |
/** * Validate a single Node by delegating to node type specific methods. * @see #testAttribute(Attr) * @see #testCDATASection(CDATASection) * @see #testComment(Comment) * @see #testDocumentType(DocumentType) * @see #testElement(Element) * @see #testEntity(Entity) * @see #testEntityReference(EntityReference) * @see #testNotation(Notation) * @see #testProcessingInstruction(ProcessingInstruction) * @see #testText(Text) */ public void testNode(Node aNode, NodeTest forTest) throws NodeTestException { switch (aNode.getNodeType()) { case Node.ATTRIBUTE_NODE: // should not happen as attributes are not exposed by DOM traversal testAttribute((Attr)aNode); break; case Node.CDATA_SECTION_NODE: testCDATASection((CDATASection)aNode); break; case Node.COMMENT_NODE: testComment((Comment)aNode); break; case Node.DOCUMENT_TYPE_NODE: testDocumentType((DocumentType)aNode); break; case Node.ELEMENT_NODE: testElement((Element)aNode); break; case Node.ENTITY_NODE: testEntity((Entity)aNode); break; case Node.ENTITY_REFERENCE_NODE: testEntityReference((EntityReference)aNode); break; case Node.NOTATION_NODE: testNotation((Notation)aNode); break; case Node.PROCESSING_INSTRUCTION_NODE: testProcessingInstruction( (ProcessingInstruction) aNode); break; case Node.TEXT_NODE: testText((Text)aNode); break; default: throw new NodeTestException("No delegate method for Node type", aNode); } }
Example 6
Source File: XmlParser.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private void checkForProcessingInstruction(Document document) throws FHIRFormatError { if (policy == ValidationPolicy.EVERYTHING && FormatUtilities.FHIR_NS.equals(document.getDocumentElement().getNamespaceURI())) { Node node = document.getFirstChild(); while (node != null) { if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) logError(line(document), col(document), "(document)", IssueType.INVALID, "No processing instructions allowed in resources", IssueSeverity.ERROR); node = node.getNextSibling(); } } }
Example 7
Source File: DTMNodeProxy.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** This is a bit of a problem in DTM, since a DTM may be a Document * Fragment and hence not have a clear-cut Document Element. We can * make it work in the well-formed cases but would that be confusing for others? * * * @see org.w3c.dom.Document */ @Override public final Element getDocumentElement() { int dochandle=dtm.getDocument(); int elementhandle=DTM.NULL; for(int kidhandle=dtm.getFirstChild(dochandle); kidhandle!=DTM.NULL; kidhandle=dtm.getNextSibling(kidhandle)) { switch(dtm.getNodeType(kidhandle)) { case Node.ELEMENT_NODE: if(elementhandle!=DTM.NULL) { elementhandle=DTM.NULL; // More than one; ill-formed. kidhandle=dtm.getLastChild(dochandle); // End loop } else elementhandle=kidhandle; break; // These are harmless; document is still wellformed case Node.COMMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: break; default: elementhandle=DTM.NULL; // ill-formed kidhandle=dtm.getLastChild(dochandle); // End loop break; } } if(elementhandle==DTM.NULL) throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); else return (Element)(dtm.getNode(elementhandle)); }
Example 8
Source File: RangeImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
void checkIndex(Node refNode, int offset) throws DOMException { if (offset < 0) { throw new DOMException( DOMException.INDEX_SIZE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null)); } int type = refNode.getNodeType(); // If the node contains text, ensure that the // offset of the range is <= to the length of the text if (type == Node.TEXT_NODE || type == Node.CDATA_SECTION_NODE || type == Node.COMMENT_NODE || type == Node.PROCESSING_INSTRUCTION_NODE) { if (offset > refNode.getNodeValue().length()) { throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null)); } } else { // Since the node is not text, ensure that the offset // is valid with respect to the number of child nodes if (offset > refNode.getChildNodes().getLength()) { throw new DOMException(DOMException.INDEX_SIZE_ERR, DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "INDEX_SIZE_ERR", null)); } } }
Example 9
Source File: XmlUtils.java From htmlunit with Apache License 2.0 | 5 votes |
/** * Copy all children from 'source' to 'dest', within the context of the specified page. * @param page the page which the nodes belong to * @param source the node to copy from * @param dest the node to copy to * @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of * DOM elements */ private static void copy(final SgmlPage page, final Node source, final DomNode dest, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) { final NodeList nodeChildren = source.getChildNodes(); for (int i = 0; i < nodeChildren.getLength(); i++) { final Node child = nodeChildren.item(i); switch (child.getNodeType()) { case Node.ELEMENT_NODE: final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap); dest.appendChild(childXml); copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap); break; case Node.TEXT_NODE: dest.appendChild(new DomText(page, child.getNodeValue())); break; case Node.CDATA_SECTION_NODE: dest.appendChild(new DomCDataSection(page, child.getNodeValue())); break; case Node.COMMENT_NODE: dest.appendChild(new DomComment(page, child.getNodeValue())); break; case Node.PROCESSING_INSTRUCTION_NODE: dest.appendChild(new DomProcessingInstruction(page, child.getNodeName(), child.getNodeValue())); break; default: if (LOG.isWarnEnabled()) { LOG.warn("NodeType " + child.getNodeType() + " (" + child.getNodeName() + ") is not yet supported."); } } } }
Example 10
Source File: DOM2SAX.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
private String getNodeTypeFromCode(short code) { String retval = null; switch (code) { case Node.ATTRIBUTE_NODE : retval = "ATTRIBUTE_NODE"; break; case Node.CDATA_SECTION_NODE : retval = "CDATA_SECTION_NODE"; break; case Node.COMMENT_NODE : retval = "COMMENT_NODE"; break; case Node.DOCUMENT_FRAGMENT_NODE : retval = "DOCUMENT_FRAGMENT_NODE"; break; case Node.DOCUMENT_NODE : retval = "DOCUMENT_NODE"; break; case Node.DOCUMENT_TYPE_NODE : retval = "DOCUMENT_TYPE_NODE"; break; case Node.ELEMENT_NODE : retval = "ELEMENT_NODE"; break; case Node.ENTITY_NODE : retval = "ENTITY_NODE"; break; case Node.ENTITY_REFERENCE_NODE : retval = "ENTITY_REFERENCE_NODE"; break; case Node.NOTATION_NODE : retval = "NOTATION_NODE"; break; case Node.PROCESSING_INSTRUCTION_NODE : retval = "PROCESSING_INSTRUCTION_NODE"; break; case Node.TEXT_NODE: retval = "TEXT_NODE"; break; } return retval; }
Example 11
Source File: DTMNodeProxy.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** This is a bit of a problem in DTM, since a DTM may be a Document * Fragment and hence not have a clear-cut Document Element. We can * make it work in the well-formed cases but would that be confusing for others? * * * @see org.w3c.dom.Document */ @Override public final Element getDocumentElement() { int dochandle=dtm.getDocument(); int elementhandle=DTM.NULL; for(int kidhandle=dtm.getFirstChild(dochandle); kidhandle!=DTM.NULL; kidhandle=dtm.getNextSibling(kidhandle)) { switch(dtm.getNodeType(kidhandle)) { case Node.ELEMENT_NODE: if(elementhandle!=DTM.NULL) { elementhandle=DTM.NULL; // More than one; ill-formed. kidhandle=dtm.getLastChild(dochandle); // End loop } else elementhandle=kidhandle; break; // These are harmless; document is still wellformed case Node.COMMENT_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.DOCUMENT_TYPE_NODE: break; default: elementhandle=DTM.NULL; // ill-formed kidhandle=dtm.getLastChild(dochandle); // End loop break; } } if(elementhandle==DTM.NULL) throw new DTMDOMException(DOMException.NOT_SUPPORTED_ERR); else return (Element)(dtm.getNode(elementhandle)); }
Example 12
Source File: DOMPrinter.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
public void print(Node node) throws XMLStreamException { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: visitDocument((Document) node); break; case Node.DOCUMENT_FRAGMENT_NODE: visitDocumentFragment((DocumentFragment) node); break; case Node.ELEMENT_NODE: visitElement((Element) node); break; case Node.TEXT_NODE: visitText((Text) node); break; case Node.CDATA_SECTION_NODE: visitCDATASection((CDATASection) node); break; case Node.PROCESSING_INSTRUCTION_NODE: visitProcessingInstruction((ProcessingInstruction) node); break; case Node.ENTITY_REFERENCE_NODE: visitReference((EntityReference) node); break; case Node.COMMENT_NODE: visitComment((Comment) node); break; case Node.DOCUMENT_TYPE_NODE: break; case Node.ATTRIBUTE_NODE: case Node.ENTITY_NODE: default: throw new XMLStreamException("Unexpected DOM Node Type " + node.getNodeType() ); } }
Example 13
Source File: AbstractDOMParser.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Record baseURI information for the Element (by adding xml:base attribute) * or for the ProcessingInstruction (by setting a baseURI field) * Non deferred DOM. * * @param node */ protected final void handleBaseURI (Node node){ if (fDocumentImpl != null) { // REVISIT: remove dependency on our implementation when // DOM L3 becomes REC String baseURI = null; short nodeType = node.getNodeType (); if (nodeType == Node.ELEMENT_NODE) { // if an element already has xml:base attribute // do nothing if (fNamespaceAware) { if (((Element)node).getAttributeNodeNS ("http://www.w3.org/XML/1998/namespace","base")!=null) { return; } } else if (((Element)node).getAttributeNode ("xml:base") != null) { return; } // retrive the baseURI from the entity reference baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI (); if (baseURI !=null && !baseURI.equals (fDocumentImpl.getDocumentURI ())) { if (fNamespaceAware) { ((Element)node).setAttributeNS ("http://www.w3.org/XML/1998/namespace", "xml:base", baseURI); } else { ((Element)node).setAttribute ("xml:base", baseURI); } } } else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI (); if (baseURI !=null && fErrorHandler != null) { DOMErrorImpl error = new DOMErrorImpl (); error.fType = "pi-base-uri-not-preserved"; error.fRelatedData = baseURI; error.fSeverity = DOMError.SEVERITY_WARNING; fErrorHandler.getErrorHandler ().handleError (error); } } } }
Example 14
Source File: DOM2DTM.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * 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. * <p> * %REVIEW% Note that as a DOM-level operation, it can be argued that this * routine _shouldn't_ perform any processing beyond what the DOM already * does, and that whitespace stripping and so on belong at the DTM level. * If you want a stripped DOM view, wrap DTM2DOM around DOM2DTM. * * @param node Node whose subtree is to be walked, gathering the * contents of all Text or CDATASection nodes. */ @SuppressWarnings("fallthrough") protected static void dispatchNodeData(Node node, org.xml.sax.ContentHandler ch, int depth) throws org.xml.sax.SAXException { 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()) { dispatchNodeData(child, ch, depth+1); } } break; case Node.PROCESSING_INSTRUCTION_NODE : // %REVIEW% case Node.COMMENT_NODE : if(0 != depth) break; // NOTE: Because this operation works in the DOM space, it does _not_ attempt // to perform Text Coalition. That should only be done in DTM space. case Node.TEXT_NODE : case Node.CDATA_SECTION_NODE : case Node.ATTRIBUTE_NODE : String str = node.getNodeValue(); if(ch instanceof CharacterNodeHandler) { ((CharacterNodeHandler)ch).characters(node); } else { ch.characters(str.toCharArray(), 0, str.length()); } break; // /* case Node.PROCESSING_INSTRUCTION_NODE : // // warning(XPATHErrorResources.WG_PARSING_AND_PREPARING); // break; */ default : // ignore break; } }
Example 15
Source File: AbstractDOMParser.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Record baseURI information for the Element (by adding xml:base attribute) * or for the ProcessingInstruction (by setting a baseURI field) * Non deferred DOM. * * @param node */ protected final void handleBaseURI (Node node){ if (fDocumentImpl != null) { // REVISIT: remove dependency on our implementation when // DOM L3 becomes REC String baseURI = null; short nodeType = node.getNodeType (); if (nodeType == Node.ELEMENT_NODE) { // if an element already has xml:base attribute // do nothing if (fNamespaceAware) { if (((Element)node).getAttributeNodeNS ("http://www.w3.org/XML/1998/namespace","base")!=null) { return; } } else if (((Element)node).getAttributeNode ("xml:base") != null) { return; } // retrive the baseURI from the entity reference baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI (); if (baseURI !=null && !baseURI.equals (fDocumentImpl.getDocumentURI ())) { if (fNamespaceAware) { ((Element)node).setAttributeNS ("http://www.w3.org/XML/1998/namespace", "xml:base", baseURI); } else { ((Element)node).setAttribute ("xml:base", baseURI); } } } else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) { baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI (); if (baseURI !=null && fErrorHandler != null) { DOMErrorImpl error = new DOMErrorImpl (); error.fType = "pi-base-uri-not-preserved"; error.fRelatedData = baseURI; error.fSeverity = DOMError.SEVERITY_WARNING; fErrorHandler.getErrorHandler ().handleError (error); } } } }
Example 16
Source File: DOM3TreeWalker.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Start processing given node * * @param node Node to process * * @throws org.xml.sax.SAXException */ protected void startNode(Node node) throws org.xml.sax.SAXException { if (node instanceof Locator) { Locator loc = (Locator) node; fLocator.setColumnNumber(loc.getColumnNumber()); fLocator.setLineNumber(loc.getLineNumber()); fLocator.setPublicId(loc.getPublicId()); fLocator.setSystemId(loc.getSystemId()); } else { fLocator.setColumnNumber(0); fLocator.setLineNumber(0); } switch (node.getNodeType()) { case Node.DOCUMENT_TYPE_NODE : serializeDocType((DocumentType) node, true); break; case Node.COMMENT_NODE : serializeComment((Comment) node); break; case Node.DOCUMENT_FRAGMENT_NODE : // Children are traversed break; case Node.DOCUMENT_NODE : break; case Node.ELEMENT_NODE : serializeElement((Element) node, true); break; case Node.PROCESSING_INSTRUCTION_NODE : serializePI((ProcessingInstruction) node); break; case Node.CDATA_SECTION_NODE : serializeCDATASection((CDATASection) node); break; case Node.TEXT_NODE : serializeText((Text) node); break; case Node.ENTITY_REFERENCE_NODE : serializeEntityReference((EntityReference) node, true); break; default : } }
Example 17
Source File: FuncHere.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * The here function returns a node-set containing the attribute or * processing instruction node or the parent element of the text node * that directly bears the XPath expression. This expression results * in an error if the containing XPath expression does not appear in the * same XML document against which the XPath expression is being evaluated. * * @param xctxt * @return the xobject * @throws javax.xml.transform.TransformerException */ @Override public XObject execute(XPathContext xctxt) throws javax.xml.transform.TransformerException { Node xpathOwnerNode = (Node) xctxt.getOwnerObject(); if (xpathOwnerNode == null) { return null; } int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode); int currentNode = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(currentNode); int docContext = dtm.getDocument(); if (DTM.NULL == docContext) { error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null); } { // check whether currentNode and the node containing the XPath expression // are in the same document Document currentDoc = XMLUtils.getOwnerDocument(dtm.getNode(currentNode)); Document xpathOwnerDoc = XMLUtils.getOwnerDocument(xpathOwnerNode); if (currentDoc != xpathOwnerDoc) { throw new TransformerException(I18n.translate("xpath.funcHere.documentsDiffer")); } } XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); NodeSetDTM nodeSet = nodes.mutableNodeset(); { int hereNode = DTM.NULL; switch (dtm.getNodeType(xpathOwnerNodeDTM)) { case Node.ATTRIBUTE_NODE : case Node.PROCESSING_INSTRUCTION_NODE : { // returns a node-set containing the attribute / processing instruction node hereNode = xpathOwnerNodeDTM; nodeSet.addNode(hereNode); break; } case Node.TEXT_NODE : { // returns a node-set containing the parent element of the // text node that directly bears the XPath expression hereNode = dtm.getParent(xpathOwnerNodeDTM); nodeSet.addNode(hereNode); break; } default : break; } } /** $todo$ Do I have to do this detach() call? */ nodeSet.detach(); return nodes; }
Example 18
Source File: FuncHere.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public XObject execute(XPathContext xctxt) throws TransformerException { Node xpathOwnerNode = (Node)xctxt.getOwnerObject(); if (xpathOwnerNode == null) { return null; } int xpathOwnerNodeDTM = xctxt.getDTMHandleFromNode(xpathOwnerNode); int currentNode = xctxt.getCurrentNode(); DTM dtm = xctxt.getDTM(currentNode); int docContext = dtm.getDocument(); if (docContext == DTM.NULL) { error(xctxt, XPATHErrorResources.ER_CONTEXT_HAS_NO_OWNERDOC, null); } // check whether currentNode and the node containing the XPath // expression are in the same document Document currentDoc = getOwnerDocument(dtm.getNode(currentNode)); Document xpathOwnerDoc = getOwnerDocument(xpathOwnerNode); if (currentDoc != xpathOwnerDoc) { throw new TransformerException("Owner documents differ"); } XNodeSet nodes = new XNodeSet(xctxt.getDTMManager()); NodeSetDTM nodeSet = nodes.mutableNodeset(); int hereNode = DTM.NULL; switch (dtm.getNodeType(xpathOwnerNodeDTM)) { case Node.ATTRIBUTE_NODE: case Node.PROCESSING_INSTRUCTION_NODE: { // returns a node-set containing the attribute / processing // instruction node hereNode = xpathOwnerNodeDTM; nodeSet.addNode(hereNode); break; } case Node.TEXT_NODE : { // returns a node-set containing the parent element of the // text node that directly bears the XPath expression hereNode = dtm.getParent(xpathOwnerNodeDTM); nodeSet.addNode(hereNode); break; } default : break; } /** $todo$ Do I have to do this detach() call? */ nodeSet.detach(); return nodes; }
Example 19
Source File: DOMSubTreeData.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * 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); } } }
Example 20
Source File: XMLUtil.java From seleniumtestsframework with Apache License 2.0 | 2 votes |
/** * Gets Node type String for a given node type constant */ public static String getNodeTypeStr(int nodeType) { switch (nodeType) { case Node.ATTRIBUTE_NODE: return "ATTRIBUTE_NODE "; case Node.CDATA_SECTION_NODE: return "CDATA_SECTION_NODE"; case Node.COMMENT_NODE: return "COMMENT_NODE"; case Node.DOCUMENT_FRAGMENT_NODE: return "DOCUMENT_FRAGMENT_NODE"; case Node.DOCUMENT_TYPE_NODE: return "DOCUMENT_TYPE_NODE"; case Node.ELEMENT_NODE: return "ELEMENT_NODE"; case Node.ENTITY_NODE: return "ENTITY_NODE"; case Node.ENTITY_REFERENCE_NODE: return "ENTITY_REFERENCE_NODE"; case Node.NOTATION_NODE: return "NOTATION_NODE"; case Node.PROCESSING_INSTRUCTION_NODE: return "PROCESSING_INSTRUCTION_NODE"; case Node.TEXT_NODE: return "TEXT_NODE"; case Node.DOCUMENT_NODE: return "DOCUMENT_NODE"; default: return "UN-INDENTIFIED NODE"; } }