Groups | Blog | Home
all groups > dotnet xml > may 2007 >

dotnet xml : Newbie question: Loading an XML document into an object


sh
5/22/2007 2:16:12 PM
I'm new to XML. I've searched for an answer to this question, but
haven't found the right one, so I'm posting here.

I've created a class named Order, which contains some data columns
(CustName, CustAddr, etc).

I also have an XML document which contains an Order's data.

Is there a VB command that will automatically place all the XML
document's elements into their appropriate place in the Order, i.e place
the CustName data from the XML doc into the CustName field of the Order
object, etc?

Something like the following

Dim Order As New Order
Order = XmlDoc.CommandThatWillPlaceEveryElementWhereItBelongs

Right now I use an XmlReader and a loop, but every time I change the
structure of the XML document, I have to modify the Reader loop. I'm
sure there is an easier way.

If you could point me to a URL that explains this, that would also be great.

sh
5/22/2007 3:13:57 PM
Thank you so much - that was what I was looking for.

There is so much to know ...


[quoted text, click to view]
Martin Honnen
5/22/2007 4:26:16 PM
[quoted text, click to view]

Look into XML serialization respectively in this case deserialization,
the class to use is System.Xml.Serialization.XmlSerializer.
<http://msdn2.microsoft.com/en-us/library/90c86ass.aspx>
If you need concrete help (for instance to apply the XML serialization
attributes to your class and its public members) then show us the class
definition and the XML you have.
--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button