List of utility methods to do XML Element Namespace
NodeList | getElementListNS(String namespace, Element element, String name) Return a list of specified namespace:Elements return element.getElementsByTagNameNS(namespace, name);
|
Element | getElementNS(String namespace, Element element, String name) Return the first named Element found - namespace aware NodeList nodeList = getElementListNS(namespace, element, name);
return (nodeList.getLength() == 0) ? null : (Element) nodeList.item(0);
|
QName | getNamespace(Element element) get Namespace String uri = element.getNamespaceURI(); String prefix = element.getPrefix() == null ? "" : element.getPrefix(); if (uri == null) { return new QName(""); } else { return new QName(uri, element.getLocalName(), prefix); |
Node | getNamespaceDeclarationOrNull(String localName, Element element) get Namespace Declaration Or Null NamedNodeMap map = element.getAttributes(); for (int i = 0; i < map.getLength(); i++) { Node node = map.item(i); String nsUri = node.getNamespaceURI(); if (nsUri == null) { continue; if ("http://www.w3.org/2000/xmlns/".equals(nsUri) && localName.equals(node.getLocalName())) { ... |
String | getNamespaceForPrefix(String prefix, Element element) get Namespace For Prefix NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); if (node instanceof Attr) { Attr attr = (Attr) node; if (XML_NS_NS.equals(attr.getNamespaceURI())) { if (attr.getLocalName().equals(prefix)) { return attr.getValue(); ... |
String | getNamespaceURI(Element element, String prefix) get Namespace URI if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { prefix = null; return element.lookupNamespaceURI(prefix); |
String | getNamespaceUriDeclaration(Element ele) get Namespace Uri Declaration NamedNodeMap attribs = ele.getAttributes(); for (int i = 0; i < attribs.getLength(); i++) { Attr attr = (Attr) attribs.item(i); if ("xmlns".equals(attr.getLocalName()) || XMLConstants.XML_NS_URI.equals(attr.getNamespaceURI())) { return attr.getTextContent(); return ""; ... |
Node | getRequiredNamespaceDeclaration(String localName, Element element) get Required Namespace Declaration Node node = getNamespaceDeclarationOrNull(localName, element); if (node == null) { throw new IllegalStateException( String.format("Namespace declaration for prefix '%s' not found", localName)); return node; |
boolean | isAppropriateElement(final Node iNode, final String iNodeName, final String iNamespace) This method determins if a node in the DOM Tree (iNode) is the node we are looking for.
boolean result = false; if (iNode.getNodeType() == Node.ATTRIBUTE_NODE) { if (iNode.getNamespaceURI() == null) { String parentsNamespace = ((Attr) iNode).getOwnerElement().getNamespaceURI(); if ((iNode.getLocalName().equals(iNodeName)) && (parentsNamespace.equals(iNamespace))) { result = true; } else { ... |
boolean | isSameElement(final String namespace, final String localName, final XMLStreamReader reader) Checks whether XML stream reader namespace and local name match the one specified in the call. return namespace.equals(reader.getNamespaceURI()) && localName.equals(reader.getLocalName());
|