By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,977 Members | 1,589 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,977 IT Pros & Developers. It's quick & easy.

XSD.EXE Question

P: n/a
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.

Feb 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"probashi" <pr******@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.
Feb 2 '06 #2

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

Thanks.

Nick Hounsome wrote:
"probashi" <pr******@hotmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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.


Feb 6 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.