Parsing SOAP messages using kXML
Gaurav Rana <[email protected]> Fri, 11 Apr 2003 14:42:16 -0700 (PDT)
| Newsgroups | gmane.comp.java.enhydra.kxml |
|---|---|
| Message-ID | <[email protected]> |
--0-209159489-1050097336=:90588
Content-Type: text/plain; charset=us-ascii
Hi,
I have got this SOAP message:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas/xmlsoap.org/soap/envelope/" >
<SOAP-ENV:Body>
<SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<PatientName xmlns="" xsi:type="xsd:string">Gaurav Rana</PatientName xmlns="" xsi:type="xsd:string">
<SerialID xmlns="" xsi:type="xsd:long">343524324</SerialID xmlns="" xsi:type="xsd:long">
<RSerialID xmlns="" xsi:type="xsd:long">42365434</RSerialID xmlns="" xsi:type="xsd:long">
</SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
</SOAP-ENV:Body>
</SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas/xmlsoap.org/soap/envelope/" >
Now I am trying to parse it using the kXML APIs. It seems that when you parse using kXML it accepts XML elements with only one word. that is it will parse <SOAP-ENV> but not <SOAP-ENV: Envelope>
XmlParser parser = new XmlParser (new InputStreamReader(input));
parser.skip();
try{
parser.read(Xml.START_TAG, "","SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas/xmlsoap.org/soap/envelope/\"");
}catch (ParseException e) {
System.out.println("Error : " + e.getLineNumber());
}
String[] result={"","",""};
while(true){
parser.skip();
ParseEvent event=parser.peek();
if(event.getType()==Xml.START_TAG){
String name= event.getName();
parser.read();
String temp = parser.readText();
System.out.println(temp);
parser.read(Xml.END_TAG,"",name);
if(name.equals("PatientName xmlns=\"\" xsi:type=\"xsd:string\"")){
result[0] = temp;
}else if(name.equals("SerialID xmlns=\"\" xsi:type=\"xsd:long\"")){
result[1] = temp;
}else if(name.equals("RSerialID xmlns=\"\" xsi:type=\"xsd:long\"")){
result[2] = temp;
}
}
else if (event.getType() == Xml.END_TAG){
parser.read(Xml.END_TAG, "","SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas/xmlsoap.org/soap/envelope/\"");
break;
}
}
Do you think I am doing it right?
Please help me. I am new to kXML.
--0-209159489-1050097336=:90588
Content-Type: text/html; charset=us-ascii
<DIV><FONT size=2>
<P>Hi, </P>
<P>I have got this SOAP message: </P>
<P><SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas/xmlsoap.org/soap/envelope/" ></P>
<P><SOAP-ENV:Body></P>
<P><SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"></P>
<P><PatientName xmlns="" xsi:type="xsd:string">Gaurav Rana</PatientName xmlns="" xsi:type="xsd:string"></P>
<P><SerialID xmlns="" xsi:type="xsd:long">343524324</SerialID xmlns="" xsi:type="xsd:long"></P>
<P><RSerialID xmlns="" xsi:type="xsd:long">42365434</RSerialID xmlns="" xsi:type="xsd:long"></P>
<P></SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"></P>
<P></SOAP-ENV:Body></P>
<P></SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas/xmlsoap.org/soap/envelope/" ></P>
<P>Now I am trying to parse it using the kXML APIs. It seems that when you parse using kXML it accepts XML elements with only one word. that is it will parse <SOAP-ENV> but not <SOAP-ENV: Envelope></P>
<P>XmlParser parser = new XmlParser (new InputStreamReader(input));</P>
<P></P>
<P>parser.skip();</P>
<P>try{</P>
<P>parser.read(Xml.START_TAG, "","SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas/xmlsoap.org/soap/envelope/\"");</P>
<P>}catch (ParseException e) {</P>
<P>System.out.println("Error : " + e.getLineNumber());</P>
<P>}</P>
<P>String[] result={"","",""};</P>
<P>while(true){</P>
<P>parser.skip();</P>
<P>ParseEvent event=parser.peek();</P>
<P></P>
<P>if(event.getType()==Xml.START_TAG){</P>
<P>String name= event.getName();</P>
<P>parser.read();</P>
<P>String temp = parser.readText();</P>
<P>System.out.println(temp);</P>
<P>parser.read(Xml.END_TAG,"",name);</P>
<P>if(name.equals("PatientName xmlns=\"\" xsi:type=\"xsd:string\"")){ </P>
<P>result[0] = temp;</P>
<P>}else if(name.equals("SerialID xmlns=\"\" xsi:type=\"xsd:long\"")){</P>
<P>result[1] = temp;</P>
<P>}else if(name.equals("RSerialID xmlns=\"\" xsi:type=\"xsd:long\"")){</P>
<P>result[2] = temp;</P>
<P>}</P>
<P>}</P>
<P>else if (event.getType() == Xml.END_TAG){</P>
<P>parser.read(Xml.END_TAG, "","SOAP-ENV:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas/xmlsoap.org/soap/envelope/\"");</P>
<P>break;</P>
<P>}</P>
<P>}</P>
<P>Do you think I am doing it right?</P>
<P>Please help me. I am new to kXML. </P></FONT></DIV>
--0-209159489-1050097336=:90588--