Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dererialising XML into an Object

Status
Not open for further replies.

Badgers

Programmer
Nov 20, 2001
187
US
Hi,

I am wanting to deserialise xml into a series of classes.

For eg;

<PurchaseOrder xmlns:xsi=" xmlns:xsd=" <ShipTo Name="Teresa Atkinson">
<Line1>1 Main St.</Line1>
<Line2>Line2</Line2>
<City>AnyTown</City>
<State>WA</State>
<Zip>00000</Zip>
<Test>Test1</Test>
</ShipTo>

[XmlRoot("PurchaseOrder", IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
}

The deserialsation doesn't work because I have not specified a namespace on the PurchaseOrder object. The xml doesn't contain a namespace...

How can you get around this, could I create a DTD from the XML and reference it as a seperate file or something....?

Any ideas would be helpful.

Thanks
 
Not sure if this will get you what you want. but a dataset can be loaded directly from XML.. you can also use it to generate a schema document.

Sorry not what i would call a complete answer, i havn't got a heap of time to think about this..

The dataset has a ReadXml method and a WriteXmlSchema method. That you might find usefull.
 
how about Linq2Xml?

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top