Example usage for javax.xml.namespace QName QName

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

Introduction

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

Prototype

public QName(String namespaceURI, String localPart, String prefix) 

Source Link

Document

QName constructor specifying the Namespace URI, local part and prefix.

If the Namespace URI is null, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = sfc.createConnection();

    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage sm = mf.createMessage();
    QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d");
    URL endpoint = new URL("http://YourSOAPServer.com");
    SOAPMessage response = connection.call(sm, endpoint);

    SOAPBody sb = response.getSOAPBody();
    java.util.Iterator iterator = sb.getChildElements(bodyName);
    while (iterator.hasNext()) {
        SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
        String val = bodyElement.getValue();
        System.out.println("The Value is:" + val);
    }/*  w  w w.  jav  a 2 s.  c  o m*/
}

From source file:SOAPResponse.java

public static void main(String[] args) {
    try {//from   ww w.  j a  v a  2s  .  c o  m
        SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = sfc.createConnection();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage sm = mf.createMessage();
        QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d");
        URL endpoint = new URL("http://YourSOAPServer.com");
        SOAPMessage response = connection.call(sm, endpoint);

        SOAPBody sb = response.getSOAPBody();
        java.util.Iterator iterator = sb.getChildElements(bodyName);
        while (iterator.hasNext()) {
            SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next();
            String val = bodyElement.getValue();
            System.out.println("The Value is:" + val);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = sfc.createConnection();

    MessageFactory mf = MessageFactory.newInstance();
    SOAPMessage sm = mf.createMessage();

    SOAPHeader sh = sm.getSOAPHeader();
    SOAPBody sb = sm.getSOAPBody();
    sh.detachNode();//w  w  w .ja  v  a  2 s  .co m
    QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d");
    SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);
    QName qn = new QName("aName");
    SOAPElement quotation = bodyElement.addChildElement(qn);

    quotation.addTextNode("TextMode");

    System.out.println("\n Soap Request:\n");
    sm.writeTo(System.out);
    System.out.println();

    URL endpoint = new URL("http://yourServer.com");
    SOAPMessage response = connection.call(sm, endpoint);
    System.out.println(response.getContentDescription());
}

From source file:SOAPRequest.java

public static void main(String[] args) {
    try {//from  w  w w . j a  va  2  s  .  c o m
        SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
        SOAPConnection connection = sfc.createConnection();

        MessageFactory mf = MessageFactory.newInstance();
        SOAPMessage sm = mf.createMessage();

        SOAPHeader sh = sm.getSOAPHeader();
        SOAPBody sb = sm.getSOAPBody();
        sh.detachNode();
        QName bodyName = new QName("http://quoteCompany.com", "GetQuote", "d");
        SOAPBodyElement bodyElement = sb.addBodyElement(bodyName);
        QName qn = new QName("aName");
        SOAPElement quotation = bodyElement.addChildElement(qn);

        quotation.addTextNode("TextMode");

        System.out.println("\n Soap Request:\n");
        sm.writeTo(System.out);
        System.out.println();

        URL endpoint = new URL("http://yourServer.com");
        SOAPMessage response = connection.call(sm, endpoint);
        System.out.println(response.getContentDescription());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Utils.java

/**
 * Build a QName from the element name/*from   w ww  .  j ava  2 s.  c o m*/
 * @param el
 * @return
 */
public static QName getQName(Element el) {
    if (el == null) {
        return null;
    } else if (el.getPrefix() != null) {
        return new QName(el.getNamespaceURI(), el.getLocalName(), el.getPrefix());
    } else {
        return new QName(el.getNamespaceURI(), el.getLocalName());
    }
}

From source file:Main.java

/**
 * @param key Local element name.//from   ww  w . jav  a 2s  .  c  o  m
 */
public static QName createQNameWithDefaultNamespace(String key) {
    return new QName(DEFAULT_NAMESPACE_URI, key, DEFAULT_NAMESPACE_PREFIX);
}

From source file:Utils.java

/**
 * Creates a QName instance from the given namespace context for the given qualifiedName
 *
 * @param element       the element to use as the namespace context
 * @param qualifiedName the fully qualified name
 * @return the QName which matches the qualifiedName
 *//*  w w  w .  j  ava2 s .c  o m*/
public static QName createQName(Element element, String qualifiedName) {
    int index = qualifiedName.indexOf(':');
    if (index >= 0) {
        String prefix = qualifiedName.substring(0, index);
        String localName = qualifiedName.substring(index + 1);
        String uri = recursiveGetAttributeValue(element, "xmlns:" + prefix);
        return new QName(uri, localName, prefix);
    } else {
        String uri = recursiveGetAttributeValue(element, "xmlns");
        if (uri != null) {
            return new QName(uri, qualifiedName);
        }
        return new QName(qualifiedName);
    }
}

From source file:Main.java

private static QName getQName(String localName, String namespaceUri, String prefix) {
    QName qname;/*www . j  a  v a  2 s.  c om*/
    if (prefix != null) {
        qname = new QName(namespaceUri, localName, prefix);
    } else {
        qname = new QName(namespaceUri, localName);
    }
    return qname;
}

From source file:Main.java

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

From source file:Main.java

public static QName getGQName(final String name) {
    return new QName("*", name, "*");
}