Example usage for javax.xml.namespace QName getLocalPart

List of usage examples for javax.xml.namespace QName getLocalPart

Introduction

In this page you can find the example usage for javax.xml.namespace QName getLocalPart.

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:Main.java

/**
 * Compare an attribute's tag name to a given name.
 *
 * @param attribute The attribute to get the tag name from.
 * @param qname The qname to compare to.
 * @return True if the attribute's tag name and namespace URI match those of the qname.
 *//*ww  w . ja  v  a2 s . c  o  m*/
public static boolean attributeHasQname(Attr attribute, QName qname) {
    return qname.getLocalPart().equals(attribute.getLocalName())
            && qname.getNamespaceURI().equals(getNamespaceUri(attribute));
}

From source file:Main.java

/**
 * Translate an XML name to a Java name.
 * [TODO]//from   ww  w .ja v  a 2s  .  c o  m
 */
public static String toJavaName(QName xmlName) {
    return xmlName.getLocalPart();
}

From source file:Main.java

private static QName cleanQName(QName in) {
    return new QName(in.getNamespaceURI(), in.getLocalPart().replaceAll("(<|>)", ""));
}

From source file:Main.java

public static QName toGQname(final QName qname) {
    return new QName("*", qname.getLocalPart(), "*");
}

From source file:Main.java

private static boolean checkNameAndNamespace(XMLEvent event, String tagName, String namespace) {
    if (event.isStartElement()) {
        StartElement element = (StartElement) event;
        QName name = element.getName();
        return tagName.equalsIgnoreCase(name.getLocalPart())
                && namespace.equalsIgnoreCase(name.getNamespaceURI());
    } else if (event.isEndElement()) {
        EndElement element = (EndElement) event;
        QName name = element.getName();
        return tagName.equalsIgnoreCase(name.getLocalPart())
                && namespace.equalsIgnoreCase(name.getNamespaceURI());
    }//from  w w w.  j a v a 2s .  c  o m

    return false;
}

From source file:Main.java

/**
 * Returns the value of the attribute with the given name.
 * //w w  w.  ja v a 2s  .c  o m
 * @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:Utils.java

public static String getAttribute(Element element, QName attName) {
    return element.getAttributeNS(attName.getNamespaceURI(), attName.getLocalPart());
}

From source file:Main.java

public final static String getEnclosingTagPair(QName qname) {
    return getEnclosingTagPair(qname.getPrefix(), qname.getLocalPart());
}

From source file:Main.java

public static boolean equal(final QName a, final QName b, final String defaultNamespace) {
    if (a.getLocalPart().equals(b.getLocalPart())) {
        String nsa = a.getNamespaceURI();
        String nsb = b.getNamespaceURI();

        if (nsa == null || nsa.length() == 0) {
            nsa = defaultNamespace;//from  w ww  .  j  a  va 2  s  .c om
        }

        if (nsb == null || nsb.length() == 0) {
            nsb = defaultNamespace;
        }

        return nsa.equals(nsb);
    }

    return false;
}

From source file:Main.java

/**
 * Determines if a node has a particular qualified name.
 * @param node the node//w w  w.j  a v  a 2 s .com
 * @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());
}