Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

xml deserialize

Status
Not open for further replies.

passertm

Programmer
Aug 2, 2005
16
AZ
what method i must use to deserialize xml object
 
Use the readObject method of the java.beans.XMLDecoder class

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
it not work. return exception.
i think it becase the xml cenerated by AXIS.

the XML looks like

<?xml version="1.0" encoding="UTF-8" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV=" xmlns:xsi=" xmlns:xsd="- <SOAP-ENV:Body>
- <ns1:getFragmentListResponse xmlns:ns1=" SOAP-ENV:encodingStyle="- <return xmlns:ns2=" xsi:type="ns2:ru_cboss_in_ws_crbt_results_FragmentRowsResult">
<count xsi:type="xsd:decimal">1131</count>
- <frgmRow xmlns:ns3=" xsi:type="ns3:Array" ns3:arrayType="ns2:ru_cboss_in_ws_crbt_rowsets_LimitedFragmentRow[10]">
- <item xsi:type="ns2:ru_cboss_in_ws_crbt_rowsets_LimitedFragmentRow">
<accessible xsi:type="xsd:decimal">1</accessible>
<dataTyp xsi:type="xsd:decimal">1</dataTyp>
<dsc xsi:type="xsd:string" xsi:nil="true" />
<fd xsi:type="xsd:string">2005-03-13 11:55:20.0</fd>
<final_time xsi:type="xsd:string" xsi:nil="true" />
<grade xsi:type="xsd:decimal" xsi:nil="true" />
<idf xsi:type="xsd:decimal">200002</idf>
<n xsi:type="xsd:decimal">8817</n>
<name xsi:type="xsd:string">200002</name>
<provider xsi:type="xsd:decimal">1</provider>
<r_in_storage xsi:type="xsd:decimal" xsi:nil="true" />
<td xsi:type="xsd:string">2018-01-01 00:00:00.0</td>
</item>
- <item xsi:type="ns2:ru_cboss_in_ws_crbt_rowsets_LimitedFragmentRow">
<accessible xsi:type="xsd:decimal">1</accessible>
<dataTyp xsi:type="xsd:decimal">1</dataTyp>
<dsc xsi:type="xsd:string" xsi:nil="true" />
<fd xsi:type="xsd:string">2005-03-13 11:55:20.0</fd>
<final_time xsi:type="xsd:string" xsi:nil="true" />
<grade xsi:type="xsd:decimal" xsi:nil="true" />
<idf xsi:type="xsd:decimal">200018</idf>
<n xsi:type="xsd:decimal">8833</n>
<name xsi:type="xsd:string">200018</name>
<provider xsi:type="xsd:decimal">1</provider>
<r_in_storage xsi:type="xsd:decimal" xsi:nil="true" />
<td xsi:type="xsd:string">2018-01-01 00:00:00.0</td>
</item>
</frgmRow>
<resCode xsi:type="xsd:int">1</resCode>
<resType xsi:type="xsd:int">0</resType>
</return>
</ns1:getFragmentListResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
 
it not work. return exception.

Perhaps you could provide a little more useful information, such as the code you are using, and the actual exception stack trace.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
OK

if i try to use for this something like
Code:
       Options options = new Options(args);
       String endpoint = "[URL unfurl="true"]http://server.com/crbtprov/Content";[/URL]
       String proc="getFragmentList";

       Service  service = new Service();
       Call     call    = (Call) service.createCall();

       call.setTargetEndpointAddress( new java.net.URL(endpoint) );
       call.setOperationName( proc );
       call.addParameter( "i1", XMLType.XSD_INT, ParameterMode.IN );
       call.addParameter( "i2", XMLType.XSD_INT, ParameterMode.IN );
       call.setReturnType( XMLType.XSD_INT );

       Integer ret = (Integer) call.invoke( new Object [] { new Integer(40), new Integer(10) });
       
       System.out.println("Got result : " + ret);


it return java.lang.NoClassDefFoundError exception

if i try use this code
Code:
   try{
            java.net.URL ur=new java.net.URL("[URL unfurl="true"]http://server.com/crbtprov/ContentProvider?invoke=getFragmentList&key=111111&n=1&rownum=10&used=1&order=1&showCount=1&access=1&lang=1");[/URL]
            java.net.URLConnection conn = ur.openConnection();
            java.beans.XMLDecoder xd= new java.beans.XMLDecoder(conn.getInputStream());
            ru.cboss.in.ws.crbt.proxy.ru_cboss_in_ws_crbt_results_FragmentRowsResult obj=(ru.cboss.in.ws.crbt.proxy.ru_cboss_in_ws_crbt_results_FragmentRowsResult)xd.readObject();
            System.out.println(obj.toString());
        }catch (Exception Ex) {
            Ex.printStackTrace();
        }

it returm exception
java.lang.Exception: Unrecognized opening tag: SOAP-ENV:Envelope xmlns:SOAP-ENV=" xmlns:xsi=" xmlns:xsd="Continuing ...
java.lang.Exception: Unrecognized opening tag: SOAP-ENV:Body
Continuing ...
java.lang.Exception: Unrecognized opening tag: ns1:getFragmentListResponse xmlns:ns1=" SOAP-ENV:encodingStyle="Continuing ...

java.lang.Exception: Unrecognized opening tag: return xmlns:ns2=" xsi:type="ns2:ru_cboss_in_ws_crbt_results_FragmentRowsResult"
Continuing ...
java.lang.Exception: Unrecognized opening tag: count xsi:type="xsd:decimal"
Continuing ...
java.lang.Exception: Unrecognized closing tag: count
Continuing ...
java.lang.Exception: Unrecognized opening tag: frgmRow xmlns:ns3=" xsi:type="ns3:Array" ns3:arrayType="ns2:ru_cboss_in_ws_crbt_rowsets_LimitedFragmentRow[10]"
Continuing ...
java.lang.Exception: Unrecognized opening tag: item xsi:type="ns2:ru_cboss_in_ws_crbt_rowsets_LimitedFragmentRow"
Continuing ...
java.lang.Exception: Unrecognized opening tag: accessible xsi:type="xsd:decimal"
Continuing ...
java.lang.Exception: Unrecognized closing tag: accessible
Continuing ...
java.lang.Exception: Unrecognized opening tag: dataTyp xsi:type="xsd:decimal"
Continuing ...
java.lang.Exception: Unrecognized closing tag: dataTyp
Continuing ...
java.lang.Exception: Unrecognized opening tag: dsc xsi:type="xsd:string" xsi:nil="true"
Continuing ...
java.lang.Exception: Unrecognized closing tag: dsc



but url looks in bowser normal

 
it return java.lang.NoClassDefFoundError exception

Which class does example 1 not find ?

As for example 2, that xml is not valid - its well-formed, but will not actually run through a validating parser.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
>Which class does example 1 not find ?
this exception comes ftom server. but i have not access to edit server side of program.
full exception look like

[/code]
AxisFault
faultCode:
faultSubcode:
faultString: [java.lang.NoClassDefFoundError]
faultActor: /crbtprov/Content
faultNode:
faultDetail:
{ [java.lang.NoClassDefFoundError]
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1712)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at TestClient.main(TestClient.java:63)
{ [java.lang.NoClassDefFoundError]
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1712)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1963)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1691)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:667)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:337)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at TestClient.main(TestClient.java:63)
Exception in thread "main"
[/code]


>As for example 2, that xml is not valid - its well-formed, but will not actually run through a validating parser.
and what do you advise me
 
If you cannot edit the server side code, then I have no idea what you are going to do.

As for creating valid xml, then again, I have no idea - I understand that Axis creates theose xml soap descriptors - perhaps you shoould go back and re-read the Axis tutorials ?


--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
can't i just get xml and deserialize it to object self??
 
Not if its not valid xml, I don't think so.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
i think it is valid xml. but decoder cant deserialize it because it serialize by soap.

i just need to know how i can deserialize xml by AXIS.
how i can create a "org.apache.axis.encoding.Deserializer" Object
 
Using XMLDecoder, you can only deserialise XML for objects serialised using the XMLEncoder class. They go together, XMLEncoder (using writeObject method), XMLDecoder (using readObject method). If the XML is produced by some other serialisation framework, then my suggestion is invalid.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
i want try deserialize it with "org.apache.axis.encoding.Deserializer" object. but i cant create this class object
 
i think it is valid xml. but decoder cant deserialize it because it serialize by soap.

As I said before - it is well formed but NOT valid. Open it with any decent XML parser (like XMLSpy) and it shows you multiple errors.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
... and it obviously needs to be valid with respect to the deserialiser since non-valid XML implies that the content won't be recognised by it.

Tim
---------------------------
"Your morbid fear of losing,
destroys the lives you're using." - Ozzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top