Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Class object - XML

Hi,

This is the scenario. A customer has id, name and purchased items. the item has item id and description. Customer can purchse any number of items. for this i have a customer class and item class. i want to produce a xml like following :

<Customers>

<Customer>

<ID>25</ID>

<Name>John</Name>

<Items>

<ItemID>1</ID>

<ItemDescription>Book1</ID>

</Items>

<Items>

<ItemID>2</ID>

<ItemDescription>Book2</ID>

</Items>

</Customer>

<Customer>

<ID>26</ID>

<Name>Tim</Name>

<Items>

<ItemID>4</ID>

<ItemDescription>Book4</ID>

</Items>

<Items>

<ItemID>1</ID>

<ItemDescription>Book1</ID>

</Items>

</Customer>

</Customers>

And i am not getting these values from db. without a dataset will it be possible..?

Thanx.

Arjun.
[1221 byte] By [Arjun] at [2007-11-11 7:32:28]
# 1 Re: Class object - XML
You can use class XmlDocument to read or write an .xml file.
For example:
XmlDocument xmlDoc = new XmlDocument();
XmlNode rootNode;
try
{
xmlDoc.Load("file.xml");//path to the file.xml
rootNode = xmlDoc.Item("Customers");

txtName = rootNode.Item("Name").InnerText;
...

itemNode = rootNode.Item("Items");
txtItemDescription = itemNode.Item("ItemDescription").InnerText;
}
catch(){}

You can find more information about XmlDocument in MSDN.
Hope this will help you.
undead142 at 2007-11-11 21:48:59 >
# 2 Re: Class object - XML
Hi undead142,

Thanx, but is there any method to just pass the class object and get the xml.
-Arjun
Arjun at 2007-11-11 21:50:04 >