Java Code Examples for org.w3c.dom.Node#ELEMENT_NODE
The following examples show how to use
org.w3c.dom.Node#ELEMENT_NODE .
These examples are extracted from open source projects.
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 Project: openjdk-8-source File: KeyInfo.java License: GNU General Public License v2.0 | 6 votes |
/** * Method lengthUnknownElement * NOTE possibly buggy. * @return the number of the UnknownElement tags */ public int lengthUnknownElement() { int res = 0; NodeList nl = this.constructionElement.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node current = nl.item(i); /** * $todo$ using this method, we don't see unknown Elements * from Signature NS; revisit */ if ((current.getNodeType() == Node.ELEMENT_NODE) && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) { res++; } } return res; }
Example 2
Source Project: RADL File: Xml.java License: Apache License 2.0 | 6 votes |
private static void append(Node node, int indentationLevel, Map<String, String> namespaces, StringBuilder builder) { switch (node.getNodeType()) { case Node.DOCUMENT_NODE: appendDocument(node, indentationLevel, namespaces, builder); break; case Node.ELEMENT_NODE: appendElement(node, indentationLevel, namespaces, builder); break; case Node.ATTRIBUTE_NODE: appendAttribute(node, namespaces, builder); break; case Node.TEXT_NODE: appendText(node, builder); break; case Node.COMMENT_NODE: appendComment(node, indentationLevel, builder); break; default: throw new UnsupportedOperationException("Unhandled node type: " + node.getNodeType()); } }
Example 3
Source Project: netbeans File: ActionMappingScanner.java License: Apache License 2.0 | 6 votes |
/** * Scan through Element named apply-for. */ void visitElement_apply_for(Element element) { // <apply-for> // element.getValue(); withPlugins = new LinkedHashSet<>(); String plugins = element.getAttribute("plugins"); if (plugins != null) { withPlugins.addAll(Arrays.asList(plugins.split(",\\s*"))); } NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element nodeElement = (Element) node; if (nodeElement.getTagName().equals("action")) { visitElement_action(nodeElement); } } } withPlugins = Collections.<String>emptySet(); }
Example 4
Source Project: mybatis-generator-core-fix File: MyBatisGeneratorConfigurationParser.java License: Apache License 2.0 | 6 votes |
private void parseJavaTypeResolver(Context context, Node node) { JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration(); context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration); Properties attributes = parseAttributes(node); String type = attributes.getProperty("type"); //$NON-NLS-1$ if (stringHasValue(type)) { javaTypeResolverConfiguration.setConfigurationType(type); } NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node childNode = nodeList.item(i); if (childNode.getNodeType() != Node.ELEMENT_NODE) { continue; } if ("property".equals(childNode.getNodeName())) { //$NON-NLS-1$ parseProperty(javaTypeResolverConfiguration, childNode); } } }
Example 5
Source Project: TencentKona-8 File: DOMDocumentSerializer.java License: GNU General Public License v2.0 | 6 votes |
/** * Serialize a {@link Document}. * * @param d the document to serialize. */ public final void serialize(Document d) throws IOException { reset(); encodeHeader(false); encodeInitialVocabulary(); final NodeList nl = d.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { final Node n = nl.item(i); switch (n.getNodeType()) { case Node.ELEMENT_NODE: serializeElement(n); break; case Node.COMMENT_NODE: serializeComment(n); break; case Node.PROCESSING_INSTRUCTION_NODE: serializeProcessingInstruction(n); break; } } encodeDocumentTermination(); }
Example 6
Source Project: openjdk-8 File: KeyInfo.java License: GNU General Public License v2.0 | 6 votes |
/** * Method lengthUnknownElement * NOTE possibly buggy. * @return the number of the UnknownElement tags */ public int lengthUnknownElement() { int res = 0; NodeList nl = this.constructionElement.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { Node current = nl.item(i); /** * $todo$ using this method, we don't see unknown Elements * from Signature NS; revisit */ if ((current.getNodeType() == Node.ELEMENT_NODE) && current.getNamespaceURI().equals(Constants.SignatureSpecNS)) { res++; } } return res; }
Example 7
Source Project: openjdk-jdk9 File: Body1_2Impl.java License: GNU General Public License v2.0 | 5 votes |
private boolean hasAnyChildElement() { Node currentNode = getFirstChild(); while (currentNode != null) { if (currentNode.getNodeType() == Node.ELEMENT_NODE) return true; currentNode = currentNode.getNextSibling(); } return false; }
Example 8
Source Project: java-n-IDE-for-Android File: ManifestMerger.java License: Apache License 2.0 | 5 votes |
/** * Checks whether the given element has a tools:merge=override or tools:merge=remove attribute. * @param node The node to check. * @return True if the element has a tools:merge=override or tools:merge=remove attribute. */ private boolean hasOverrideOrRemoveTag(@Nullable Node node) { if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { return false; } NamedNodeMap attrs = node.getAttributes(); Node merge = attrs.getNamedItemNS(TOOLS_URI, MERGE_ATTR); String value = merge == null ? null : merge.getNodeValue(); return MERGE_OVERRIDE.equals(value) || MERGE_REMOVE.equals(value); }
Example 9
Source Project: buck File: XmlElement.java License: Apache License 2.0 | 5 votes |
private Optional<String> findAndCompareNode( @NonNull XmlElement otherElement, @NonNull List<Node> otherElementChildren, @NonNull XmlElement childNode) { Optional<String> message = Optional.absent(); for (Node potentialNode : otherElementChildren) { if (potentialNode.getNodeType() == Node.ELEMENT_NODE) { @NonNull XmlElement otherChildNode = new XmlElement((Element) potentialNode, mDocument); if (childNode.getType() == otherChildNode.getType()) { // check if this element uses a key. if (childNode.getType().getNodeKeyResolver().getKeyAttributesNames() .isEmpty()) { // no key... try all the other elements, if we find one equal, we are done. message = childNode.compareTo(otherChildNode); if (!message.isPresent()) { return Optional.absent(); } } else { // key... if (childNode.getKey() == null) { // other key MUST also be null. if (otherChildNode.getKey() == null) { return childNode.compareTo(otherChildNode); } } else { if (childNode.getKey().equals(otherChildNode.getKey())) { return childNode.compareTo(otherChildNode); } } } } } } return message.isPresent() ? message : Optional.of(String.format("Child %1$s not found in document %2$s", childNode.getId(), otherElement.printPosition())); }
Example 10
Source Project: xenon File: TorqueXmlParser.java License: Apache License 2.0 | 5 votes |
/** * Parses job info from "qstat -x" * * @param data * the stream to get the xml data from * @return a list containing all queue names found * @throws XenonException * if the file could not be parsed * @throws XenonException * if the server version is not compatible with this adaptor */ protected Map<String, Map<String, String>> parseJobInfos(String data) throws XenonException { if (data.trim().isEmpty()) { return new HashMap<>(); } Document document = parseDocument(data); LOGGER.debug("root node of xml file: " + document.getDocumentElement().getNodeName()); NodeList nodes = document.getDocumentElement().getChildNodes(); int numNodes = nodes.getLength(); Map<String, Map<String, String>> result = new HashMap<>(); for (int i = 0; i < numNodes; i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Map<String, String> jobInfo = new HashMap<>(); recursiveMapFromElement(node, jobInfo); String jobId = jobInfo.get("Job_Id"); if (jobId == null || jobId.isEmpty()) { throw new XenonException(ADAPTOR_NAME, "found job in queue with no job number"); } result.put(jobId, jobInfo); } } return result; }
Example 11
Source Project: anthelion File: RelTagParser.java License: Apache License 2.0 | 5 votes |
void parse(Node node) { if (node.getNodeType() == Node.ELEMENT_NODE) { // Look for <a> tag if ("a".equalsIgnoreCase(node.getNodeName())) { NamedNodeMap attrs = node.getAttributes(); Node hrefNode = attrs.getNamedItem("href"); // Checks that it contains a href attribute if (hrefNode != null) { Node relNode = attrs.getNamedItem("rel"); // Checks that it contains a rel attribute too if (relNode != null) { // Finaly checks that rel=tag if ("tag".equalsIgnoreCase(relNode.getNodeValue())) { String tag = parseTag(hrefNode.getNodeValue()); if (!StringUtil.isEmpty(tag)) { tags.add(tag); } } } } } } // Recurse NodeList children = node.getChildNodes(); for (int i=0; children != null && i<children.getLength(); i++) { parse(children.item(i)); } }
Example 12
Source Project: JDKSourceCode1.8 File: DTMNodeProxy.java License: MIT License | 4 votes |
/** * * DOM Level 3 * Look up the prefix associated to the given namespace URI, starting from this node. * * @param namespaceURI * @return the prefix for the namespace */ @Override public String lookupPrefix(String namespaceURI){ // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == null) { return null; } short type = this.getNodeType(); switch (type) { /* case Node.ELEMENT_NODE: { String namespace = this.getNamespaceURI(); // to flip out children return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); } case Node.DOCUMENT_NODE:{ return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupPrefix(namespaceURI); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupPrefix(namespaceURI); } */ return null; } } }
Example 13
Source Project: olingo-odata4 File: ClientODataDeserializerImpl.java License: Apache License 2.0 | 4 votes |
private List<List<String>> getAllSchemaNameSpace(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException{ List<List<String>> schemaNameSpaces = new ArrayList <>(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setFeature( "http://xml.org/sax/features/namespaces", true); dbFactory.setFeature( "http://apache.org/xml/features/validation/schema", false); dbFactory.setFeature( "http://apache.org/xml/features/validation/schema-full-checking", true); dbFactory.setFeature( "http://xml.org/sax/features/external-general-entities", false); dbFactory.setFeature( "http://xml.org/sax/features/external-parameter-entities", false); dbFactory.setFeature( "http://apache.org/xml/features/disallow-doctype-decl", true); dbFactory.setFeature( "http://javax.xml.XMLConstants/feature/secure-processing", true); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inputStream); doc.getDocumentElement().normalize(); NodeList nList = doc.getElementsByTagName(SCHEMA); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); List<String> nameSpaces = new ArrayList <>(); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; NamedNodeMap attributes = eElement.getAttributes(); int len = attributes.getLength(); for(int i =0;i<len;i++){ // check for all atributes begining with name xmlns or xmlns: String attrName = attributes.item(i).getNodeName(); if( XMLNS.equals(attrName) || attrName.startsWith(XMLNS+":")){ nameSpaces.add(attributes.item(i).getNodeValue()); } } } schemaNameSpaces.add(nameSpaces); } return schemaNameSpaces; }
Example 14
Source Project: openjdk-jdk9 File: DOM2DTMdefaultNamespaceDeclarationNode.java License: GNU General Public License v2.0 | 4 votes |
/** * * DOM Level 3 - Experimental: * Look up the prefix associated to the given namespace URI, starting from this node. * * @param namespaceURI * @return the prefix for the namespace */ public String lookupPrefix(String namespaceURI){ // REVISIT: When Namespaces 1.1 comes out this may not be true // Prefix can't be bound to null namespace if (namespaceURI == null) { return null; } short type = this.getNodeType(); switch (type) { /* case Node.ELEMENT_NODE: { String namespace = this.getNamespaceURI(); // to flip out children return lookupNamespacePrefix(namespaceURI, (ElementImpl)this); } case Node.DOCUMENT_NODE:{ return((NodeImpl)((Document)this).getDocumentElement()).lookupPrefix(namespaceURI); } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupPrefix(namespaceURI); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupPrefix(namespaceURI); } */ return null; } } }
Example 15
Source Project: javaide File: ResourceItem.java License: GNU General Public License v3.0 | 4 votes |
@NonNull private static String getMarkupText(@NonNull NodeList children) { StringBuilder sb = new StringBuilder(); for (int i = 0, n = children.getLength(); i < n; i++) { Node child = children.item(i); short nodeType = child.getNodeType(); switch (nodeType) { case Node.ELEMENT_NODE: { Element element = (Element) child; String tagName = element.getTagName(); sb.append('<'); sb.append(tagName); NamedNodeMap attributes = element.getAttributes(); int attributeCount = attributes.getLength(); if (attributeCount > 0) { for (int j = 0; j < attributeCount; j++) { Node attribute = attributes.item(j); sb.append(' '); sb.append(attribute.getNodeName()); sb.append('=').append('"'); XmlUtils.appendXmlAttributeValue(sb, attribute.getNodeValue()); sb.append('"'); } } sb.append('>'); NodeList childNodes = child.getChildNodes(); if (childNodes.getLength() > 0) { sb.append(getMarkupText(childNodes)); } sb.append('<'); sb.append('/'); sb.append(tagName); sb.append('>'); break; } case Node.TEXT_NODE: sb.append(child.getNodeValue()); break; case Node.CDATA_SECTION_NODE: sb.append(child.getNodeValue()); break; } } return sb.toString(); }
Example 16
Source Project: hottub File: XMLUtils.java License: GNU General Public License v2.0 | 4 votes |
/** * This method is a tree-search to help prevent against wrapping attacks. It checks that no other * Element than the given "knownElement" argument has an ID attribute that matches the "value" * argument, which is the ID value of "knownElement". If this is the case then "false" is returned. */ public static boolean protectAgainstWrappingAttack( Node startNode, Element knownElement, String value ) { Node startParent = startNode.getParentNode(); Node processedNode = null; String id = value.trim(); if (!id.isEmpty() && id.charAt(0) == '#') { id = id.substring(1); } while (startNode != null) { if (startNode.getNodeType() == Node.ELEMENT_NODE) { Element se = (Element) startNode; NamedNodeMap attributes = se.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Attr attr = (Attr)attributes.item(i); if (attr.isId() && id.equals(attr.getValue()) && se != knownElement) { log.log(java.util.logging.Level.FINE, "Multiple elements with the same 'Id' attribute value!"); return false; } } } } processedNode = startNode; startNode = startNode.getFirstChild(); // no child, this node is done. if (startNode == null) { // close node processing, get sibling startNode = processedNode.getNextSibling(); } // no more siblings, get parent, all children // of parent are processed. while (startNode == null) { processedNode = processedNode.getParentNode(); if (processedNode == startParent) { return true; } // close parent node processing (processed node now) startNode = processedNode.getNextSibling(); } } return true; }
Example 17
Source Project: jdk8u60 File: DTMNodeProxy.java License: GNU General Public License v2.0 | 4 votes |
/** * DOM Level 3 * Look up the namespace URI associated to the given prefix, starting from this node. * Use lookupNamespaceURI(null) to lookup the default namespace * * @param namespaceURI * @return th URI for the namespace * @since DOM Level 3 */ @Override public String lookupNamespaceURI(String specifiedPrefix) { short type = this.getNodeType(); switch (type) { case Node.ELEMENT_NODE : { String namespace = this.getNamespaceURI(); String prefix = this.getPrefix(); if (namespace !=null) { // REVISIT: is it possible that prefix is empty string? if (specifiedPrefix== null && prefix==specifiedPrefix) { // looking for default namespace return namespace; } else if (prefix != null && prefix.equals(specifiedPrefix)) { // non default namespace return namespace; } } if (this.hasAttributes()) { NamedNodeMap map = this.getAttributes(); int length = map.getLength(); for (int i=0;i<length;i++) { Node attr = map.item(i); String attrPrefix = attr.getPrefix(); String value = attr.getNodeValue(); namespace = attr.getNamespaceURI(); if (namespace !=null && namespace.equals("http://www.w3.org/2000/xmlns/")) { // at this point we are dealing with DOM Level 2 nodes only if (specifiedPrefix == null && attr.getNodeName().equals("xmlns")) { // default namespace return value; } else if (attrPrefix !=null && attrPrefix.equals("xmlns") && attr.getLocalName().equals(specifiedPrefix)) { // non default namespace return value; } } } } /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } /* case Node.DOCUMENT_NODE : { return((NodeImpl)((Document)this).getDocumentElement()).lookupNamespaceURI(specifiedPrefix) ; } */ case Node.ENTITY_NODE : case Node.NOTATION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: // type is unknown return null; case Node.ATTRIBUTE_NODE:{ if (this.getOwnerElement().getNodeType() == Node.ELEMENT_NODE) { return getOwnerElement().lookupNamespaceURI(specifiedPrefix); } return null; } default:{ /* NodeImpl ancestor = (NodeImpl)getElementAncestor(this); if (ancestor != null) { return ancestor.lookupNamespaceURI(specifiedPrefix); } */ return null; } } }
Example 18
Source Project: org.hl7.fhir.core File: CDANarrativeFormat.java License: Apache License 2.0 | 4 votes |
private void processChildNode(Node n, XhtmlNode xn) throws FHIRException { switch (n.getNodeType()) { case Node.ATTRIBUTE_NODE: case Node.CDATA_SECTION_NODE: case Node.DOCUMENT_FRAGMENT_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.DOCUMENT_NODE: case Node.ENTITY_NODE: case Node.PROCESSING_INSTRUCTION_NODE: case Node.NOTATION_NODE: return; case Node.ENTITY_REFERENCE_NODE: throw new Error("Not handled yet"); case Node.COMMENT_NODE: xn.addComment(n.getTextContent()); return; case Node.TEXT_NODE: if (!Utilities.isWhitespace(n.getTextContent())) xn.addText(n.getTextContent()); return; case Node.ELEMENT_NODE: Element e = (Element) n; if (n.getNodeName().equals("br")) processBreak(e, xn); else if (n.getNodeName().equals("caption")) processCaption(e, xn); else if (n.getNodeName().equals("col")) processCol(e, xn); else if (n.getNodeName().equals("colgroup")) processColGroup(e, xn); else if (n.getNodeName().equals("content")) processContent(e, xn); else if (n.getNodeName().equals("footnote")) processFootNote(e, xn); else if (n.getNodeName().equals("footnoteRef")) processFootNodeRef(e, xn); else if (n.getNodeName().equals("item")) processItem(e, xn); else if (n.getNodeName().equals("linkHtml")) processlinkHtml(e, xn); else if (n.getNodeName().equals("list")) processList(e, xn); else if (n.getNodeName().equals("paragraph")) processParagraph(e, xn); else if (n.getNodeName().equals("renderMultiMedia")) processRenderMultiMedia(e, xn); else if (n.getNodeName().equals("sub")) processSub(e, xn); else if (n.getNodeName().equals("sup")) processSup(e, xn); else if (n.getNodeName().equals("table")) processTable(e, xn); else if (n.getNodeName().equals("tbody")) processTBody(e, xn); else if (n.getNodeName().equals("td")) processTd(e, xn); else if (n.getNodeName().equals("tfoot")) processTFoot(e, xn); else if (n.getNodeName().equals("th")) processTh(e, xn); else if (n.getNodeName().equals("thead")) processTHead(e, xn); else if (n.getNodeName().equals("tr")) processTr(e, xn); else throw new FHIRException("Unknown element "+n.getNodeName()); } }
Example 19
Source Project: openjdk-jdk8u File: DOMKeyInfo.java License: GNU General Public License v2.0 | 4 votes |
/** * Creates a <code>DOMKeyInfo</code> from XML. * * @param kiElem KeyInfo element */ public DOMKeyInfo(Element kiElem, XMLCryptoContext context, Provider provider) throws MarshalException { // get Id attribute, if specified Attr attr = kiElem.getAttributeNodeNS(null, "Id"); if (attr != null) { id = attr.getValue(); kiElem.setIdAttributeNode(attr, true); } else { id = null; } // get all children nodes NodeList nl = kiElem.getChildNodes(); int length = nl.getLength(); if (length < 1) { throw new MarshalException ("KeyInfo must contain at least one type"); } List<XMLStructure> content = new ArrayList<XMLStructure>(length); for (int i = 0; i < length; i++) { Node child = nl.item(i); // ignore all non-Element nodes if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } Element childElem = (Element)child; String localName = childElem.getLocalName(); if (localName.equals("X509Data")) { content.add(new DOMX509Data(childElem)); } else if (localName.equals("KeyName")) { content.add(new DOMKeyName(childElem)); } else if (localName.equals("KeyValue")) { content.add(DOMKeyValue.unmarshal(childElem)); } else if (localName.equals("RetrievalMethod")) { content.add(new DOMRetrievalMethod(childElem, context, provider)); } else if (localName.equals("PGPData")) { content.add(new DOMPGPData(childElem)); } else { //may be MgmtData, SPKIData or element from other namespace content.add(new javax.xml.crypto.dom.DOMStructure((childElem))); } } keyInfoTypes = Collections.unmodifiableList(content); }
Example 20
Source Project: openjdk-jdk9 File: DOMUtils.java License: GNU General Public License v2.0 | 3 votes |
/** * Returns the last child element of the specified node, or null if there * is no such element. * * @param node the node * @return the last child element of the specified node, or null if there * is no such element * @throws NullPointerException if <code>node == null</code> */ public static Element getLastChildElement(Node node) { Node child = node.getLastChild(); while (child != null && child.getNodeType() != Node.ELEMENT_NODE) { child = child.getPreviousSibling(); } return (Element)child; }