XSD.EXE Question

P

probashi

I am getting xml like this from our vendor:
<XXX>
<XXXDATASET ROWS="00005">
<XXXROW>
<XXXColum ID="CustomerName">John Smith</XXXColum >
<XXXColum ID="AddressLine1">Road One</XXXColum >
<XXXColum ID="Zip">123456</XXXColum >
</XXXROW>
<XXXROW></XXXROW>
....
</XXXDATASET>
</XXX>

I want to de serialize this to Customer Object something like:

Class Customer
{
public string CustomerName;
public string AddressLine1;
public string Zip;
}

I want to use XSD.EXE tool for generating the class and use .NET XML
Serializer.

When I use the XSD tool to generate the class, I got the following:

public class XXXXXXDATASETXXXROWXXXColum {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ID;

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value;
}

Is there any way to de serialize to my Class Customer
Instead of class XXXXXXDATASETXXXROWXXXColum.
 
N

Nick Hounsome

probashi said:
I am getting xml like this from our vendor:
<XXX>
<XXXDATASET ROWS="00005">
<XXXROW>
<XXXColum ID="CustomerName">John Smith</XXXColum >
<XXXColum ID="AddressLine1">Road One</XXXColum >
<XXXColum ID="Zip">123456</XXXColum >
</XXXROW>
<XXXROW></XXXROW>
....
</XXXDATASET>
</XXX>

I want to de serialize this to Customer Object something like:

Class Customer
{
public string CustomerName;
public string AddressLine1;
public string Zip;
}

I want to use XSD.EXE tool for generating the class and use .NET XML
Serializer.

When I use the XSD tool to generate the class, I got the following:

public class XXXXXXDATASETXXXROWXXXColum {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ID;

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value;
}

Is there any way to de serialize to my Class Customer
Instead of class XXXXXXDATASETXXXROWXXXColum.

First check whether an xsd file exists for the format and generate from that
rather than the xml if possible as it may give extra restrictions that
cannot be inferred from an example.

Second edit the output and anotate with XmlElementAttribute using the
ElementName property.

There are a whole bunch of attributes in System.Xml.Serialization that you
can use to alter the mapping from XML to code.

If the schema is out of your control and you anticipate that new elements
might be added in future then you are better off reading it into an
XPathDocument and just picking out the elements that you want.
 
P

probashi

I am looking for the attribute that I can use to map
<XXXColum ID="CustomerName">John Smith</XXXColum >
to Customer.CustomerName property.

Thanks.

Nick said:
probashi said:
I am getting xml like this from our vendor:
<XXX>
<XXXDATASET ROWS="00005">
<XXXROW>
<XXXColum ID="CustomerName">John Smith</XXXColum >
<XXXColum ID="AddressLine1">Road One</XXXColum >
<XXXColum ID="Zip">123456</XXXColum >
</XXXROW>
<XXXROW></XXXROW>
....
</XXXDATASET>
</XXX>

I want to de serialize this to Customer Object something like:

Class Customer
{
public string CustomerName;
public string AddressLine1;
public string Zip;
}

I want to use XSD.EXE tool for generating the class and use .NET XML
Serializer.

When I use the XSD tool to generate the class, I got the following:

public class XXXXXXDATASETXXXROWXXXColum {

/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string ID;

/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value;
}

Is there any way to de serialize to my Class Customer
Instead of class XXXXXXDATASETXXXROWXXXColum.

First check whether an xsd file exists for the format and generate from that
rather than the xml if possible as it may give extra restrictions that
cannot be inferred from an example.

Second edit the output and anotate with XmlElementAttribute using the
ElementName property.

There are a whole bunch of attributes in System.Xml.Serialization that you
can use to alter the mapping from XML to code.

If the schema is out of your control and you anticipate that new elements
might be added in future then you are better off reading it into an
XPathDocument and just picking out the elements that you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top