Friday 15 February 2013

c# - There is an error in XML document (27, 4) when deserializing XML from MemoryStream class -



c# - There is an error in XML document (27, 4) when deserializing XML from MemoryStream class -

when receiving xml info api exception thrown.

{"the string '' not valid allxsd value."}

there error in xml document (27, 4)

the xml info looks ok , have used code before parsing similar xml. i'm not sure causing exception.

the returned xml is

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <agentinventory xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:n1="demo.org.uk/demo/customsstatus" xmlns:n2="demo.org.uk/demo/unlocation" xmlns:n3="demo.org.uk/demo/aircarrier" xmlns="demo.org.uk/demo/agentinventory"> <shed>tax</shed> <arrivalport> <n2:iataportcode>lhr</n2:iataportcode> </arrivalport> <masterairwaybillprefix>125</masterairwaybillprefix> <masterairwaybillnumber>25051155</masterairwaybillnumber> <nominatedagent>drb</nominatedagent> <originport> <n2:iataportcode>bos</n2:iataportcode> </originport> <destinationport> <n2:iataportcode>lhr</n2:iataportcode> </destinationport> <aircarrier> <n3:carriercode>ba</n3:carriercode> </aircarrier> <flightnumber>123</flightnumber> <flightdate>2011-05-25t00:00:00z</flightdate> <npx>10</npx> <npr>0</npr> <grossweight>123.0</grossweight> <goodsdescription>books</goodsdescription> <sdc>t</sdc> <status1set></status1set> <status2set>true</status2set> <ccscreationtime>2011-05-25t21:17:00z</ccscreationtime> <customsstatus> <n1:code>cc</n1:code> <n1:statustext>customs cleared</n1:statustext> </customsstatus> <customssummarytext>tred clearance</customssummarytext> <customssummarytime>2011-05-25t21:30:00z</customssummarytime> <agentreference>rs cfsp </agentreference> <isertsprearrival>false</isertsprearrival> <isagentprearrival>false</isagentprearrival> <isdeleted>false</isdeleted> <finalised></finalised> <createdon>2011-05-25t21:17:18.167z</createdon> <modifiedon>2011-05-25t21:30:20.37z</modifiedon> </agentinventory>

the code used deserialize xml looks this:

var storexmlinventoryreturndata = returninventorydata.returnvalue; if (storexmlinventoryreturndata != null) { //deserialize xml variable agentinventory myinventoryresponse = null; xmlserializer xmlserializer = new xmlserializer(typeof(agentinventory)); memorystream memstream = new memorystream(encoding.utf8.getbytes(storexmlinventoryreturndata)); myinventoryresponse = (agentinventory)xmlserializer.deserialize(memstream); console.writeline( @"\n\n\n inventory homecoming info awb: {0}-{1} \n\n destination port: {2} \n arrival port: {3} \n carrier: {4} \n flight no: {5} \n flight date: {6} \n customers status: {7} \n npx: {8} \n npr {9} \n sdc code: {10} \n\n nail key exit...." , myinventoryresponse.masterairwaybillprefix, myinventoryresponse.masterairwaybillnumber, myinventoryresponse.destinationport, myinventoryresponse.arrivalport, myinventoryresponse.aircarrier, myinventoryresponse.flightnumber, myinventoryresponse.flightdate, myinventoryresponse.customsstatus, myinventoryresponse.npx, myinventoryresponse.npr, myinventoryresponse.sdc, myinventoryresponse.grossweight, myinventoryresponse.goodsdescription ); console.readline(); } else { console.write("no info returned"); }

the line throws exception is

myinventoryresponse = (agentinventory)xmlserializer.deserialize(memstream);

c# xml memorystream

No comments:

Post a Comment