Deserialize XML returned as string

I have a string (sXML) containing XML code available to me from a web service.  I want to deserialize this string returning what is contained within the <RECORD> tags.  The web service is provided to me by another company, and I have no control over that.
// .aspx
        var serializer = new XmlSerializer(typeof(_13100));
        var reader = new StringReader(sXML);

        _13100 ds;
        ds = (_13100)serializer.Deserialize(reader);

        Response.Write(ds.CurBal + "<br />");
        Response.Write(ds.DepositStatus + "<br />");

// _13100 Class
[Serializable]
[XmlRoot("XAPI_RESPONSE")]
public class _13100
{
    [XmlElement("CurBal")]
    public double CurBal { get; set; }
    [XmlElement("DepositStatus")]
    public string DepositStatus { get; set; }
}

// sXML value
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<XAPI_RESPONSE>\n  <RESPONSE>\n    <RECORD><CurBal>67719.85</CurBal><DepositStatus>Active             </DepositStatus></RECORD><Sequence>1</Sequence><ReferenceNo>0331091308013</ReferenceNo><XapiTranCode>13100</XapiTranCode><ReturnCode>0</ReturnCode><OvrdInfo1 /><OvrdInfo2 /><PostingMethod>R </PostingMethod><LogPTID>338127</LogPTID><UserReturnCode>0</UserReturnCode><UserReturnCodeDesc />\n  </RESPONSE>\n  <Rc>0</Rc>\n  <SQL>0</SQL>\n  <XmDbStatus>D</XmDbStatus>\n  <PrimDbAvailable>1</PrimDbAvailable>\n  <HRESULT>0</HRESULT>\n</XAPI_RESPONSE>"

Open in new window

LVL 3
hawks4everAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
For your _13100 object (cool name!) you should have following input string:
string sXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?><XAPI_RESPONSE><CurBal>67719.85</CurBal><DepositStatus>Active</DepositStatus></XAPI_RESPONSE>";

For deserializing your input, you have to create objects with nested objects
e.g.
public class XAPI_RESPONSE
public class RESPONSE
public class RECORD // what you call now _13100
0
lazyberezovskyCommented:

[XmlRoot("XAPI_RESPONSE")]
public class XAPI_RESPONSE
{
    [XmlElement("RESPONSE")]
    public RESPONSE Response { get; set; }
}

[XmlRoot("RESPONSE")]
public class RESPONSE
{
    [XmlElement("RECORD")]
    public RECORD Record { get; set; }        
}

[XmlRoot("RECORD")]
public class RECORD
{
    [XmlElement("CurBal")]
    public double CurBal { get; set; }
    [XmlElement("DepositStatus")]
    public string DepositStatus { get; set; }
}


var serializer = new XmlSerializer(typeof(XAPI_RESPONSE));
var reader = new StringReader(sXML);
XAPI_RESPONSE xr = (XAPI_RESPONSE)serializer.Deserialize(reader);
Response.Write(xr.Response.Record.CurBal + "<br />");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hawks4everAuthor Commented:
Thank you!  Now I'm getting the following error on Line 54:
The string '2008-05-10 00:00:00.000' is not a valid AllXsd value.

I didn't include my entire _13100 class for brevity because nearly all of the elements are either double or string, but I do have a datetime.  Any ideas how to avoid this error?
Line 52:         var serializer = new XmlSerializer(typeof(XAPI_RESPONSE));
Line 53:         var reader = new StringReader(sXML);
Line 54:         XAPI_RESPONSE ds = (XAPI_RESPONSE)serializer.Deserialize(reader);
Line 55: 
Line 56:         Response.Write(ds.Response.Record.CurBal + "<br />");

Open in new window

0
lazyberezovskyCommented:
Xml expects datetime in specific formats
http://www.w3schools.com/Schema/schema_dtypes_date.asp

So, I'd advice you to deserialize this value to property of String type. And later convert it to datetime via DateTime.Parse or Conver.ToDateTime
0
hawks4everAuthor Commented:
Thank you very much!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.