axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Garth Keesler <gar...@gdcjk.com>
Subject Re: Parsing Returned XML String
Date Mon, 15 Jan 2007 13:37:10 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thilina,<br>
<br>
Thanx for the reply. Attached is the modified and cleaned-up original
code as well as the result of the Ant build/run. It still appears that
all of the returned XML is being treated as a single string and does
not break out correctly when parsed. I probably misread your
instructions so feel free to correct. Ignore the Java warning since it
is on an unrelated source file.<br>
<br>
Thanx,<br>
Garth<br>
<br>
import org.apache.axiom.om.*;<br>
import org.apache.axiom.om.OMAbstractFactory;
<br>
import org.apache.axiom.om.OMElement;
<br>
import org.apache.axiom.om.OMFactory;
<br>
import org.apache.axiom.om.OMNamespace;
<br>
import org.apache.axis2.addressing.EndpointReference;
<br>
import org.apache.axis2.client.Options;
<br>
import org.apache.axis2.client.ServiceClient;<br>
import java.util.Iterator;<br>
import javax.xml.stream.*;<br>
import java.io.*;<br>
&nbsp;<br>
public class Scenario1Client {
<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; public static void main(String[] args) throws Exception {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ServiceClient client
= new ServiceClient();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // create option object
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Options opts = new
Options();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //setting target EPR
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opts.setTo(new
EndpointReference(<a class="moz-txt-link-rfc2396E" href="http://appsrv:8080/axis2/services/wsVendor">"http://appsrv:8080/axis2/services/wsVendor"</a>));
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Setting action ,and
which can be found from the wsdl of the
service
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opts.setAction("urn:wsgetVendor");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client.setOptions(opts);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement res = client.sendReceive(createPayLoad());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Iterator children =
res.getChildren();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (children.hasNext())<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
OMNode node = (OMNode) children.next();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(node.toString());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp; public static OMElement createPayLoad() {
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMFactory fac = OMAbstractFactory.getOMFactory();
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMNamespace omNs =
fac.createOMNamespace(<a class="moz-txt-link-rfc2396E" href="http://ttna.com/xsd">"http://ttna.com/xsd"</a>,
"ns1");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement method =
fac.createOMElement("wsgetVendor", omNs);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement value = fac.createOMElement("value",
omNs);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; value.setText("hsv");
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method.addChild(value);
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return method;
<br>
&nbsp;&nbsp;&nbsp; }
<br>
&nbsp;<br>
}
<br>
<br>
garthk@gdkws:~/dev/MyService$ ant<br>
Buildfile: build.xml<br>
<br>
clean:<br>
<br>
init:<br>
<br>
compile:<br>
&nbsp;&nbsp;&nbsp; [javac] Compiling 6 source files to
/home/garthk/dev/MyService/build/classes<br>
&nbsp;&nbsp;&nbsp; [javac] /home/garthk/dev/MyService/src/Scenario6Client.java:19:
warning: unmappable character for encoding UTF8<br>
&nbsp;&nbsp;&nbsp; [javac]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
//assigning message context&#65533;s option object into
instance variable<br>
&nbsp;&nbsp;&nbsp; [javac]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
^<br>
&nbsp;&nbsp;&nbsp; [javac] 1 warning<br>
<br>
compress:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [jar] Building jar:
/home/garthk/dev/MyService/build/bin/WSClient.jar<br>
<br>
test1:<br>
&nbsp;&nbsp;&nbsp;&nbsp; [java] &lt;ns:return
xmlns:ns=<a class="moz-txt-link-rfc2396E" href="http://ttna.com/xsd">"http://ttna.com/xsd"</a>&gt;&lt;address1
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;address2
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;address3
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;city1
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;city2
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;country
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;mailCode
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;region
xmlns:xsi=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema-instance">"http://www.w3.org/2001/XMLSchema-instance"</a>
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>
xsi:nil="true" /&gt;&lt;rid
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>&gt;0&lt;/rid&gt;&lt;userID
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>&gt;garthk&lt;/userID&gt;&lt;vendorID
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>&gt;hsv&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/vendorID&gt;&lt;vendorName
xmlns=<a class="moz-txt-link-rfc2396E" href="http://tier1.ttna.com/xsd">"http://tier1.ttna.com/xsd"</a>&gt;Huntsville&lt;/vendorName&gt;&lt;/ns:return&gt;<br>
<br>
main:<br>
&nbsp;&nbsp;&nbsp;&nbsp; [echo] <br>
&nbsp;&nbsp;&nbsp;&nbsp; [echo]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Building the project...<br>
&nbsp;&nbsp;&nbsp;&nbsp; [echo] <br>
<br>
BUILD SUCCESSFUL<br>
Total time: 2 seconds<br>
<br>
<br>
<br>
<br>
Thilina Gunarathne wrote:
<blockquote
 cite="mide9115cfd0701150520y3374e288j36d2ee473f15dc05@mail.gmail.com"
 type="cite">Hi Garth,
  <br>
You should be able to do this with Axiom itself...
  <br>
  <blockquote type="cite">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
opts.setAction("urn:wsgetVendor");
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; client.setOptions(opts);
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OMElement
res = client.sendReceive(createPayLoad());
    <br>
  </blockquote>
You can use the "res" OMElement to access it's children...
  <br>
Try adding the following to here..
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Iterator
children = res.getChildren();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while (children.hasNext())
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
OMNode node = (OMNode) children.next();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(node.toString());
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
  <br>
  <br>
  <blockquote type="cite">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
XMLStreamReader reader =
XMLInputFactory.newInstance()
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
.createXMLStreamReader(
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
new
    <br>
ByteArrayInputStream(res.toString().getBytes()));
    <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StAXOMBuilder
builder = new StAXOMBuilder(reader); // get the
root
    <br>
  </blockquote>
No need to do the above, since you already have a Axiom in place with
  <br>
the web service response....
  <br>
  <br>
You can find some articles &amp; tutorials about Axiom from here [1].
  <br>
  <br>
Thanks,
  <br>
Thilina
  <br>
[1] <a class="moz-txt-link-freetext" href="http://www.wso2.org/projects/axiom/java">http://www.wso2.org/projects/axiom/java</a>
  <br>
</blockquote>
<br>
</body>
</html>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Mime
View raw message