Click here to Skip to main content
15,396,859 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
XML
Hi there,
i've a problem with a strange xml and I don't know how to deserialize it.

This is the xml:

<pre lang="xml">
<?xml version="1.0" encoding="UTF-8"?>
<CRMMessage language="en_US" currency="USD" isTrustedSAT="false" hostversion="1.00">
<RequestCode>GetCustomer</RequestCode>
<ResponseCode>A</ResponseCode>
<ResultSet>
<ResultSetMetaData>
<RSColumn name="PRIMARYPOSREF" type="string" nullable="true"></RSColumn>
<RSColumn name="ACTIVE" type="boolean" nullable="false"></RSColumn>
<RSColumn name="firstName" type="string" nullable="true"></RSColumn>
<RSColumn name="LastName" type="string" nullable="true"></RSColumn>
<RSColumn name="postalCode" type="string" nullable="true"></RSColumn>
<RSColumn name="city" type="string" nullable="true"></RSColumn>
<RSColumn name="county" type="string" nullable="true"></RSColumn>
<RSColumn name="addressline1" type="string" nullable="true"></RSColumn>
<RSColumn name="addressline2" type="string" nullable="true"></RSColumn>
<RSColumn name="organizationname" type="string" nullable="true"></RSColumn>
</ResultSetMetaData>
<Rows>
<Row id="168209">
<Col />
<Col>1</Col>
<Col>John</Col>
<Col>Doe</Col>
<Col />
<Col />
<Col />
<Col />
<Col />
<Col />
</Row>
</Rows>
</ResultSet>
</CRMMessage>

</pre>

The xml will return always one row.

Thanks for your help.
Davide.
Posted
Comments
Sergey Alexandrovich Kryukov 13-Nov-13 12:01pm
   
First of all, how did you end up with this strange XML (what's so strange?)? Perhaps you rather need to do both serialization and deserialization? Generally, those operations are symmetric and hence should be done in a single place. If is not so, most likely you are solving a wrong problem, which you simply should not solve.
—SA
tgrt 13-Nov-13 15:26pm
   
The XML you provided only has one row (id 168209). So always having one row is the correct behavior.
Fred Flams 14-Nov-13 4:58am
   
You should post that as an answer, since the provided XML really does contain only one row....
I know that sound silly, since the clues were there since the beginning...
Davide Ardizzola 14-Nov-13 5:23am
   
I've not understand what you mean.
tgrt 14-Nov-13 8:18am
   
I would, but then it would just get downvoted. I think he's saying that the XML will always return one row, but the problem is that he doesn't know how to deserialize the XML.
Davide Ardizzola 14-Nov-13 8:39am
   
correct, i don't know how to deserialize it.
Davide Ardizzola 13-Nov-13 15:47pm
   
I call a webservice giving a customer id (in the example the ID 168209) and the web service answer to me with Customer FirstName, LastName, ZIP, City...

I get the xml from a webservice.
I only need to deserialize it.
johannesnestler 14-Nov-13 9:37am
   
The question is: deserialize to what? It doesn't sound like you created an object model representing the information from the XML. So I see two options. you need only specifc information: just parse the XML and read the needed specific infos. or create a corresponding object model (an XSD or DTD of the used schema would be great help when doing this), then deserialize to this model.
Davide Ardizzola 14-Nov-13 10:03am
   
I've generated the xsd and than the container class but when i deserialize i get always a error message: Error in XML document (2, 2).

This is the class:
<pre lang="CS">
//------------------------------------------------------------------------------
// <auto-generated>
// Il codice è stato generato da uno strumento.
// Versione runtime:2.0.50727.5472
//
// Le modifiche apportate a questo file possono provocare un comportamento non corretto e andranno perse se
// il codice viene rigenerato.
//
//------------------------------------------------------------------------------

using System.Xml.Serialization;

namespace TestWebService
{
//
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
//


/// <remarks>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class CRMMessage
{

private string requestCodeField;

private string responseCodeField;

private CRMMessageResultSet[] resultSetField;

private string languageField;

private string currencyField;

private string isTrustedSATField;

private string hostversionField;

/// <remarks>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string RequestCode
{
get { return this.requestCodeField; }
set { this.requestCodeField = value; }
}

/// <remarks>
[System.Xml.Serialization.XmlElementAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string ResponseCode
{
get { return this.responseCodeField; }
set { this.responseCodeField = value; }
}

/// <remarks>
[System.Xml.Serialization.XmlElementAttribute("ResultSet", Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
public CRMMessageResultSet[] ResultSet
{
get { return this.resultSetField; }
set { this.resultSetField = value; }
}

/// <remarks>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string language
{
get { return this.languageField; }
set { this.languageField = value; }
}

/// <remarks>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string currency
{
get { return this.currencyField; }
set { this.currencyField = value; }
}

/// <remarks>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string isTrustedSAT
{
get { return this.isTrustedSATField; }
set { this.isTrustedSATField = value; }
}

/// <remarks>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string hostversion
{
get { return this.hostversionField; }
set { this.hostversionField = value; }
}
}

/// <remarks>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public partial class CRMMessageResultSet
{

private CRMMessageResultSetResultSetMetaDataRSColumn[][] resultSetMetaDataField;

private CRMMessageResultSetRowsRow[][] rowsField;

/// <remarks>
[System.Xml.Serialization.XmlArrayAttribute(Form = System.Xml.Schema.XmlSchemaForm.Unqualified)
tgrt 14-Nov-13 23:04pm
   
What is the inner exception?

That error should have an inner exception, and it usually gives you the answer. I'm guessing the problem is that you're asking it to deserialize the root element CRMMessage, but the actual root is the pre.

1 solution

I've solved making the classes with this tool: Simple XML to Code.

Bye!
Davide.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900