Reading an XML file into a dataset

M

Maziar Aflatoun

Hi everyone,

I like to use the dataset object for reading the following XML.

<?xml version="1.0" encoding="utf-8"?>
<ORDERS>
<ORDER>
<GENERALCONTACT>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Company>Company1</Company>
</GENERALCONTACT>
<PRODUCTS>
<PRODUCT>
<NAME>Product A</NAME>
<PRICE>$10.99</PRICE>
</PRODUCT>
<PRODUCT>
<NAME>Product B</NAME>
<PRICE>$5.99</PRICE>
</PRODUCT>
</PRODUCTS>
</ORDER>

<ORDER>
<GENERALCONTACT>
<FirstName>FirstName2</FirstName>
<LastName>LastName2</LastName>
<Company>Company2</Company>
</GENERALCONTACT>
<PRODUCTS>
<PRODUCT>
<NAME>Product C</NAME>
<PRICE>$21.99</PRICE>
</PRODUCT>
<PRODUCT>
<NAME>Product D</NAME>
<PRICE>$6.99</PRICE>
</PRODUCT>
</PRODUCTS>
</ORDER>
</ORDERS>

Question 1. How do I just read the products for 1 order only? if I do
dsXMLOrder.Tables["PRODUCT"].Rows.Count;

it will return 4.

Question 2. If I was to add attributes to the above XML. Is it possible to
read attributes from a dataset loaded from an XML file?

Thank you
Maz A.
 
C

Craig Deelsnyder

inline

Hi everyone,

I like to use the dataset object for reading the following XML.

<?xml version="1.0" encoding="utf-8"?>
<ORDERS>
<ORDER>
<GENERALCONTACT>
<FirstName>FirstName1</FirstName>
<LastName>LastName1</LastName>
<Company>Company1</Company>
</GENERALCONTACT>
<PRODUCTS>
<PRODUCT>
<NAME>Product A</NAME>
<PRICE>$10.99</PRICE>
</PRODUCT>
<PRODUCT>
<NAME>Product B</NAME>
<PRICE>$5.99</PRICE>
</PRODUCT>
</PRODUCTS>
</ORDER>

<ORDER>
<GENERALCONTACT>
<FirstName>FirstName2</FirstName>
<LastName>LastName2</LastName>
<Company>Company2</Company>
</GENERALCONTACT>
<PRODUCTS>
<PRODUCT>
<NAME>Product C</NAME>
<PRICE>$21.99</PRICE>
</PRODUCT>
<PRODUCT>
<NAME>Product D</NAME>
<PRICE>$6.99</PRICE>
</PRODUCT>
</PRODUCTS>
</ORDER>
</ORDERS>

Question 1. How do I just read the products for 1 order only? if I do
dsXMLOrder.Tables["PRODUCT"].Rows.Count;

it will return 4.

Use a DataView on the PRODUCT table, it has a select method.

http://msdn.microsoft.com/library/d...ef/html/frlrfSystemDataDataViewClassTopic.asp
Question 2. If I was to add attributes to the above XML. Is it possible
to
read attributes from a dataset loaded from an XML file?

Thank you
Maz A.

I doubt it; the only attributes I know of that would be understood are the
standard schema attributes that define type information (e.g. that a
column is a string, or integer, etc.).
 

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

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top