List of usage examples for javax.xml.namespace QName getNamespaceURI
public String getNamespaceURI()
Get the Namespace URI of this QName
.
From source file:Main.java
/** * Determines if a node has a particular qualified name. * @param node the node//w ww . java 2 s.c o m * @param qname the qualified name * @return true if the node has the given qualified name, false if not */ public static boolean hasQName(Node node, QName qname) { return qname.getNamespaceURI().equals(node.getNamespaceURI()) && qname.getLocalPart().equals(node.getLocalName()); }
From source file:Main.java
private static QName cleanQName(QName in) { return new QName(in.getNamespaceURI(), in.getLocalPart().replaceAll("(<|>)", "")); }
From source file:Main.java
/** * Find a Node with a given QName// w w w . java 2s.com * * @param node parent node * @param name QName of the child we need to find * @return child node */ public static Node findNode(Node node, QName name) { if (name.getNamespaceURI().equals(node.getNamespaceURI()) && name.getLocalPart().equals(node.getLocalName())) return node; NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node ret = findNode(children.item(i), name); if (ret != null) return ret; } return null; }
From source file:Main.java
/** * Finds a Node with a given QNameb./*from w w w . j ava 2 s . com*/ * * @param node parent node * @param name QName of the child we need to find * @return Returns child node. */ public static Node findNode(Node node, QName name) { if (name.getNamespaceURI().equals(node.getNamespaceURI()) && name.getLocalPart().equals(node.getLocalName())) { return node; } NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node ret = findNode(children.item(i), name); if (ret != null) { return ret; } } return null; }
From source file:Utils.java
public static String getAttribute(Element element, QName attName) { return element.getAttributeNS(attName.getNamespaceURI(), attName.getLocalPart()); }
From source file:Main.java
/** * Return the qualified name, that is to say the prefix -if any- with the * local name./*from w ww . j av a 2 s. co m*/ * * @param qName * The QName. * @return A string that looks like "<tt>prefix:localName</tt>" or " * <tt>NCName</tt>". */ public static String getQualifiedName(QName qName) { if (!XMLConstants.NULL_NS_URI.equals(qName.getNamespaceURI()) && !XMLConstants.DEFAULT_NS_PREFIX.equals(qName.getPrefix())) { return qName.getPrefix() + ":" + qName.getLocalPart(); } else { return qName.getLocalPart(); } }
From source file:Main.java
/** * Returns the value of the attribute with the given name. * /*from ww w.j a va2 s.c om*/ * @param reader The xml stream reader * @param name The name of the attribute. * @return The value of the attribute, or <code>null</code> if the * attribute wasn't present. */ public static final String attributeValue(XMLStreamReader reader, QName name) { return reader.getAttributeValue(name.getNamespaceURI(), name.getLocalPart()); }
From source file:Main.java
/** * @param key Fully qualified element name. *//*from w w w . j av a2 s .c o m*/ public static Element createElement(QName key) { return createDocument().createElementNS(key.getNamespaceURI(), key.getPrefix() + ":" + key.getLocalPart()); }
From source file:Utils.java
/** * Return the first element child with the specified qualified name. * /*from w w w . j a va 2s. c o m*/ * @param parent * @param q * @return */ public static Element getFirstChildWithName(Element parent, QName q) { String ns = q.getNamespaceURI(); String lp = q.getLocalPart(); return getFirstChildWithName(parent, ns, lp); }
From source file:Main.java
public static String convertToXpath(String qname) { QName name = QName.valueOf(qname); if ("".equals(name.getNamespaceURI())) { return "//" + name.getLocalPart(); } else {/*www .jav a2 s . c o m*/ return "//*[local-name()='" + name.getLocalPart() + "' and namespace-uri()='" + name.getNamespaceURI() + "']"; } }