XML and the Dataset

D

Daren Hawes

Hi I have a XML File and a Dataset

<?xml version="1.0" standalone="yes"?>
<Tank xmlns="http://www.tempuri.org/Tank.xsd">
<Tank>
<TankName>Tank One</TankName>
<TankLocation>Lounge Room</TankLocation>
<TankSize>140 Litres / 40 Gallons</TankSize>
<TankContents>FOWLR (Reef Tank)</TankContents>
<TankLightingType>Fluoros</TankLightingType>
<TankFilterType>Canister</TankFilterType>
<TankSkimmerType>Side Mount</TankSkimmerType>
<TankDescription>corner mounted</TankDescription>
<TankStartDate>2004-11-10</TankStartDate>
</Tank>
</Tank>

dim dsTestDataset as new Dataset
dsTestDataset.ReadXML("test.xml")

Now it is loaded. Thats fine.

How can I access the for example TankSize direct from the Dataset.

dim strTankSize as String = dsTestDataset???????.???

I have tried data views and gotten myself very confused.

Thx
 
G

Guest

Hi Daren

C# code (easier to copy and paste your string in - let me know if you need
the VB translation):

HTH

Nigel Armstrong

string s = @"<?xml version='1.0' standalone='yes'?>
<Tank xmlns='http://www.tempuri.org/Tank.xsd'>
<Tank>
<TankName>Tank One</TankName>
<TankLocation>Lounge Room</TankLocation>
<TankSize>140 Litres / 40 Gallons</TankSize>
<TankContents>FOWLR (Reef Tank)</TankContents>
<TankLightingType>Fluoros</TankLightingType>
<TankFilterType>Canister</TankFilterType>
<TankSkimmerType>Side Mount</TankSkimmerType>
<TankDescription>corner mounted</TankDescription>
<TankStartDate>2004-11-10</TankStartDate>
</Tank>
</Tank>";

System.IO.StringReader sr = new System.IO.StringReader(s);
System.Data.DataSet d = new DataSet();
d.ReadXml(sr);

MessageBox.Show(d.GetXml());
// Tables / Rows / Columns - ToString() to get the string representation
MessageBox.Show(d.Tables["Tank"].Rows[0]["TankSize"].ToString());
 
D

Daren Hawes

Thanks the VB version would be a little clearer, but I think I get the
drift.

Also just to clarify the XML file will be a seperate file added to the
din folder so I have to use (In VB)

Imports System.IO

DIM path as String = Directory.CurrentDirectory()
DIM ds as new Dataset
ds.ReadXML(path & "\file.xml")

..
..
..

DIM TankName as String = ds.Tables(0)"Tank".Rows(0)"TankName".ToString()

Is the above correct? I am not near my VS or I would try!!

Thx Heaps
 

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

Top