Got it! I tracked it down in "Java & XML" by Brett McLaughlin, published by O'Reilly.

BTW, the book makes use of Apache Xerces in its examples and that's what I used.

Thanx,
Garth

Garth Keesler wrote:
The following xml text is what gets returned from the web service call. I have tried a variety of methods to extract the values, as shown in the included client source, using examples found on the web but with no success. They all return the OMElement from the web service invocation as a string with no children or siblings. Eclipse, however, seems to understand the text as xml just fine, allowing me to use the graphical view to view the elements and their values.

What tool(s) should I use to extract the values?

Thanx,
Garth

<start of XML>

<ns:return xmlns:ns="http://ttna.com/xsd">
    <address1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <address2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <address3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <city1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <city2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <country xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <mailCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <region xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://tier1.ttna.com/xsd" xsi:nil="true" />
    <rid xmlns="http://tier1.ttna.com/xsd">0</rid>
    <userID xmlns="http://tier1.ttna.com/xsd">garthk</userID>
    <vendorID xmlns="http://tier1.ttna.com/xsd">hsv</vendorID>
    <vendorName xmlns="http://tier1.ttna.com/xsd">
        Huntsville
    </vendorName>
</ns:return>

<end of XML>
<start of java>

package com.ttna;

import org.apache.axiom.om.*;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import java.util.Iterator;
import javax.xml.stream.*;
import java.io.*;
import org.xml.sax.InputSource;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.w3c.dom.*;
//import javax.xml.parsers.DocumentBuilder;
//import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.*;

public class Scenario1Client
{

    public static void main(String[] args) throws Exception
    {
        ServiceClient client = new ServiceClient();
        // create option object
        Options opts = new Options();
        // setting target EPR
        opts.setTo(new EndpointReference(
                "http://appsrv:8080/axis2/services/wsVendor"));
        // Setting action ,and which can be found from the wsdl of the service
        opts.setAction("urn:wsgetVendor");
        client.setOptions(opts);
        OMElement res = client.sendReceive(createPayLoad());

        XMLStreamReader reader = XMLInputFactory.newInstance()
                .createXMLStreamReader(
                        new ByteArrayInputStream(res.toString().getBytes()));
        StAXOMBuilder builder = new StAXOMBuilder(reader); // get the root
                                                            // element (in this
                                                            // case the
        OMElement documentElement = builder.getDocumentElement();
        OMDocument doc = builder.getDocument();
//        OMNode node = doc.getFirstOMChild();
//        OMNode sib = node.getNextOMSibling();
//        System.out.println("sib = " + sib.toString());
//        System.out.println("count = " + doc.getAttributeCount());
        // dump the out put to console with caching
        Iterator children = documentElement.getChildren();
        while (children.hasNext())
        {
            OMNode node = (OMNode) children.next();
            System.out.println(node.toString());
        }

        /*
         * try { DocumentBuilderFactory factory = DocumentBuilderFactory
         * .newInstance(); DocumentBuilder db = factory.newDocumentBuilder();
         * InputSource inStream = new InputSource();
         * inStream.setCharacterStream(new StringReader(res.toString()));
         * Document doc1 = db.parse(inStream); System.out.println(" doc1.version = " +
         * doc1.getXmlVersion()); System.out.println(" doc1.baseuri = " +
         * doc1.getBaseURI()); System.out.println(" doc1.docuri = " +
         * doc1.getDocumentURI()); System.out.println(" doc1.inputencoding = " +
         * doc1.getInputEncoding()); System.out.println(" doc1.localname = " +
         * doc1.getLocalName()); System.out.println(" doc1.namespace = " +
         * doc1.getNamespaceURI()); System.out.println(" doc1.nodename = " +
         * doc1.getNodeName()); System.out.println(" doc1.value = " +
         * doc1.getNodeValue()); System.out.println(" doc1.prefix = " +
         * doc1.getPrefix()); System.out.println(" doc1.textcontent = " +
         * doc1.getTextContent()); System.out.println(" doc1.xmlencoding = " +
         * doc1.getXmlEncoding()); System.out.println(" doc1.type = " +
         * doc1.getNodeType()); Element ele = doc1.getElementById("address1");
         * System.out.println(" ele = " + ele.toString()); } catch (Exception e) {
         * System.out.println(e); }
         */
    }

    public static OMElement createPayLoad()
    {
        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://ttna.com/xsd", "ns1");
        OMElement method = fac.createOMElement("wsgetVendor", omNs);
        OMElement value = fac.createOMElement("value", omNs);
        value.setText("hsv");
        method.addChild(value);
        return method;
    }



<end of java>}

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] .

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to