List of usage examples for org.w3c.dom Node getNamespaceURI
public String getNamespaceURI();
null
if it is unspecified (see ). From source file:Main.java
private static void convert(Node toCopy, Node saveTo, Document doc) { Node newNode;//from www. j a v a 2 s . co m switch (toCopy.getNodeType()) { case Node.ELEMENT_NODE: Element newElement = doc.createElementNS(toCopy.getNamespaceURI(), toCopy.getNodeName()); newNode = newElement; Element baseElement = (Element) toCopy; NamedNodeMap children = baseElement.getAttributes(); for (int i = 0; i < children.getLength(); i++) { convertAttribute((Attr) children.item(i), newElement, doc); } break; case Node.TEXT_NODE: newNode = doc.createTextNode(toCopy.getTextContent()); break; default: newNode = null; } if (newNode != null) { NodeList children = toCopy.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { convert(children.item(i), newNode, doc); } saveTo.appendChild(newNode); } }
From source file:Main.java
/** Finds and returns the last child node with the given qualified name. */ public static Element getLastChildElementNS(Node parent, String[][] elemNames) { // search for node Node child = parent.getLastChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { for (int i = 0; i < elemNames.length; i++) { String uri = child.getNamespaceURI(); if (uri != null && uri.equals(elemNames[i][0]) && child.getLocalName().equals(elemNames[i][1])) { return (Element) child; }/* w w w . j a v a 2s .co m*/ } } child = child.getPreviousSibling(); } // not found return null; }
From source file:Main.java
/** Finds and returns the first child node with the given qualified name. */ public static Element getFirstChildElementNS(Node parent, String[][] elemNames) { // search for node Node child = parent.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { for (int i = 0; i < elemNames.length; i++) { String uri = child.getNamespaceURI(); if (uri != null && uri.equals(elemNames[i][0]) && child.getLocalName().equals(elemNames[i][1])) { return (Element) child; }/*from ww w.j a va2 s . com*/ } } child = child.getNextSibling(); } // not found return null; }
From source file:Main.java
public static List<Element> elements(final Element father, final String ns, final String localName) { final List<Element> matchingElements = new ArrayList<Element>(); final NodeList nl = father.getChildNodes(); for (int i = 0; i < nl.getLength(); i++) { final Node n = nl.item(i); if (n instanceof Element && n.getLocalName() != null && n.getLocalName().equals(localName) && n.getNamespaceURI() != null && n.getNamespaceURI().equals(ns)) { matchingElements.add((Element) n); }/* ww w.j av a2s. c o m*/ } return matchingElements; }
From source file:com.evolveum.midpoint.util.QNameUtil.java
public static boolean compareQName(QName qname, Node node) { return (qname.getNamespaceURI().equals(node.getNamespaceURI()) && qname.getLocalPart().equals(node.getLocalName())); }
From source file:Main.java
/** Finds and returns the next sibling node with the given qualified name. */ public static Element getNextSiblingElementNS(Node node, String[][] elemNames) { // search for node Node sibling = node.getNextSibling(); while (sibling != null) { if (sibling.getNodeType() == Node.ELEMENT_NODE) { for (int i = 0; i < elemNames.length; i++) { String uri = sibling.getNamespaceURI(); if (uri != null && uri.equals(elemNames[i][0]) && sibling.getLocalName().equals(elemNames[i][1])) { return (Element) sibling; }//from w w w . j a v a 2 s .co m } } sibling = sibling.getNextSibling(); } // not found return null; }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addAttributes(Element relevantElement, Node instanceNode) { NamedNodeMap instanceAttributes = instanceNode.getAttributes(); for (int index = 0; index < instanceAttributes.getLength(); index++) { Node instanceAttr = (Node) instanceAttributes.item(index); if (isEnabled(instanceAttr)) { if (instanceAttr.getNamespaceURI() == null) { relevantElement.setAttribute(instanceAttr.getNodeName(), instanceAttr.getNodeValue()); } else { relevantElement.setAttributeNS(instanceAttr.getNamespaceURI(), instanceAttr.getNodeName(), instanceAttr.getNodeValue()); }// ww w .j av a 2 s . c om } } }
From source file:Main.java
@Nullable public static String getNamespaceURI(@Nullable final Node aNode) { if (aNode instanceof Document) { // Recurse into document element return getNamespaceURI(((Document) aNode).getDocumentElement()); }// w w w. java 2 s . c om if (aNode != null) return aNode.getNamespaceURI(); return null; }
From source file:Main.java
/** * Access all immediate child elements inside the given Element * * @param element the starting element, cannot be null. * @param namespaceURI name space of the child element to look for, * cannot be null. Use "*" to match all namespaces * @param elemName the name of the child element to look for, * cannot be null./*w w w. jav a2 s. c o m*/ * @return array of all immediate child element inside element, or * an array of size zero if no child elements are found. */ public static Element[] getChildElements(Element element, String namespaceURI, String elemName) { NodeList list = element.getChildNodes(); int len = list.getLength(); ArrayList<Node> array = new ArrayList<Node>(len); for (int i = 0; i < len; i++) { Node n = list.item(i); if (n.getNodeType() == Node.ELEMENT_NODE) { if (elemName.equals(n.getLocalName()) && ("*".equals(namespaceURI) || namespaceURI.equals(n.getNamespaceURI()))) { array.add(n); } } } Element[] elems = new Element[array.size()]; return (Element[]) array.toArray(elems); }
From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java
private static void addElement(Element relevantParent, Node instanceNode) { Document relevantDocument = relevantParent.getOwnerDocument(); Element relevantElement;// w w w. jav a 2 s . c om if (instanceNode.getNamespaceURI() == null) { relevantElement = relevantDocument.createElement(instanceNode.getNodeName()); } else { relevantElement = relevantDocument.createElementNS(instanceNode.getNamespaceURI(), instanceNode.getNodeName()); } // needed in instance serializer ... relevantElement.setUserData("", instanceNode.getUserData(""), null); relevantParent.appendChild(relevantElement); addAttributes(relevantElement, instanceNode); addChildren(relevantElement, instanceNode); }