List of usage examples for org.w3c.dom Node ELEMENT_NODE
short ELEMENT_NODE
To view the source code for org.w3c.dom Node ELEMENT_NODE.
Click Source Link
Element
. From source file:Main.java
private static List<Element> getJsModulesForSpecificPlatform(Document doc, String platformName) { List<Element> suitableJsModules = new ArrayList<Element>(); Element documentElement = doc.getDocumentElement(); NodeList childNodes = documentElement.getChildNodes(); for (int i = 0; i < childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; if (isJsModuleElement(element)) { // Common js-module for all types of projects (ios, android, wp8 etc.) suitableJsModules.add(element); } else if (isPlatformElement(element) && (element.getAttribute(ATTRIBUTE_NAME) != null) && element.getAttribute(ATTRIBUTE_NAME).equals(platformName)) { // platform-specific js-module List<Element> androidJsModules = getChildElementsByName(element, TAG_JS_MODULE); suitableJsModules.addAll(androidJsModules); }/*from w w w. ja v a 2 s. c om*/ } } return suitableJsModules; }
From source file:Main.java
/** * Returns an array containing the element objects in the provided node list. * //from w w w . j ava 2s. c o m * @param nodeList The DOM node objects to extract elements from. * @return The array of DOM elements found in the node list. */ @SuppressWarnings("unchecked") public static Element[] getElementsOfNodeList(NodeList nodeList) { Element[] ret = null; @SuppressWarnings("rawtypes") Vector v = new Vector(); for (int n = 0; n < nodeList.getLength(); n++) { Node item = nodeList.item(n); if (item.getNodeType() == Node.ELEMENT_NODE) { v.addElement(item); } } ret = new Element[v.size()]; for (int n = 0; n < ret.length; n++) { ret[n] = (Element) v.elementAt(n); } return ret; }
From source file:Main.java
/** * The method extractChildElementNodes extracts all child elements of a * node./*w w w . j a v a 2 s. c om*/ * * @param aParentNode * a parent node * * @return a list of child elements */ static List<Node> extractChildElementNodes(Node aParentNode) { return extractChildNodes(aParentNode, Node.ELEMENT_NODE); }
From source file:Main.java
public static List<Element> getElementsByTagName(Element parent, String name, boolean localOnly) { List<Element> ret = new ArrayList<Element>(); if (!localOnly) { NodeList elementList = parent.getElementsByTagName(name); for (int i = 0; i < elementList.getLength(); i++) { ret.add((Element) elementList.item(i)); }//w ww. ja va 2s.c om } else { NodeList childList = parent.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { if (childList.item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element child = (Element) childList.item(i); if (child.getTagName().equals(name)) ret.add(child); } } return ret; }
From source file:Main.java
/** * Clone given Node into target Document. If targe is null, same Document will be used. * If deep is specified, all children below will also be cloned. */// www.jav a2s. c o m public static Node cloneNode(Node node, Document target, boolean deep) throws DOMException { if (target == null || node.getOwnerDocument() == target) // same Document return node.cloneNode(deep); else { //DOM level 2 provides this in Document, so once xalan switches to that, //we can take out all the below and just call target.importNode(node, deep); //For now, we implement based on the javadocs for importNode Node newNode; int nodeType = node.getNodeType(); switch (nodeType) { case Node.ATTRIBUTE_NODE: newNode = target.createAttribute(node.getNodeName()); break; case Node.DOCUMENT_FRAGMENT_NODE: newNode = target.createDocumentFragment(); break; case Node.ELEMENT_NODE: Element newElement = target.createElement(node.getNodeName()); NamedNodeMap nodeAttr = node.getAttributes(); if (nodeAttr != null) for (int i = 0; i < nodeAttr.getLength(); i++) { Attr attr = (Attr) nodeAttr.item(i); if (attr.getSpecified()) { Attr newAttr = (Attr) cloneNode(attr, target, true); newElement.setAttributeNode(newAttr); } } newNode = newElement; break; case Node.ENTITY_REFERENCE_NODE: newNode = target.createEntityReference(node.getNodeName()); break; case Node.PROCESSING_INSTRUCTION_NODE: newNode = target.createProcessingInstruction(node.getNodeName(), node.getNodeValue()); break; case Node.TEXT_NODE: newNode = target.createTextNode(node.getNodeValue()); break; case Node.CDATA_SECTION_NODE: newNode = target.createCDATASection(node.getNodeValue()); break; case Node.COMMENT_NODE: newNode = target.createComment(node.getNodeValue()); break; case Node.NOTATION_NODE: case Node.ENTITY_NODE: case Node.DOCUMENT_TYPE_NODE: case Node.DOCUMENT_NODE: default: throw new IllegalArgumentException("Importing of " + node + " not supported yet"); } if (deep) for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) newNode.appendChild(cloneNode(child, target, true)); return newNode; } }
From source file:Main.java
/** * Get the next right sibling that is an element. *//*from w w w . ja va 2 s. c om*/ public static Element getNextElement(Node node) { Element found = null; if (node != null) { for (Node next = node.getNextSibling(); next != null && found == null; next = next.getNextSibling()) { if (next.getNodeType() == Node.ELEMENT_NODE) { found = (Element) next; } } } return found; }
From source file:Main.java
public static List<Element> elements(Element root, String namepaceUri, String localName) { List<Element> L = new ArrayList<Element>(); if (root == null) return L; for (Node n1 = root.getFirstChild(); n1 != null; n1 = n1.getNextSibling()) { if (n1.getNodeType() != Node.ELEMENT_NODE) continue; Element e2 = Element.class.cast(n1); if (namepaceUri.equals(e2.getNamespaceURI()) && e2.getLocalName().equals(localName)) { L.add(e2);/* www . j a v a2 s. co m*/ } } return L; }
From source file:Main.java
public static List<Element> getElementsByTagNameNS(Element parent, String uri, String name, boolean localOnly) { List<Element> ret = new ArrayList<Element>(); if (!localOnly) { NodeList elementList = parent.getElementsByTagNameNS(uri, name); for (int i = 0; i < elementList.getLength(); i++) { ret.add((Element) elementList.item(i)); }/*from w ww.ja v a 2s. co m*/ } else { NodeList childList = parent.getChildNodes(); for (int i = 0; i < childList.getLength(); i++) { if (childList.item(i).getNodeType() != Node.ELEMENT_NODE) continue; Element child = (Element) childList.item(i); if ((uri.equals("*") || child.getNamespaceURI().equals(uri)) && ((child.getLocalName() == null && uri.equals("*") && child.getTagName().equals(name)) || child.getLocalName().equals(name))) ret.add(child); } } return ret; }
From source file:Main.java
protected static List<Element> createElementList(Element element) { List<Element> elementList = new ArrayList<>(); NodeList childNodes = element.getChildNodes(); int numChildren = childNodes.getLength(); for (int i = 0; i < numChildren; i++) { Node childNode = childNodes.item(i); if (childNode.getNodeType() != Node.ELEMENT_NODE) { continue; }/*from w w w . ja va2 s . c om*/ elementList.add((Element) childNode); } return elementList; }
From source file:Main.java
public static Element getChildElementByLocalName(Element parentElem, String localName) { Node child = parentElem.getFirstChild(); while (child != null) { if ((child.getNodeType() == Node.ELEMENT_NODE) && getLocalName(child).equals(localName)) { return (Element) child; }/*from w w w . ja va 2 s.c o m*/ child = child.getNextSibling(); } return null; }