Home All Groups Group Topic Archive Search About
Author
26 Nov 2004 1:51 AM
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





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Author
26 Nov 2004 5:13 PM
Nigel Armstrong
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());

Show quote
"Daren Hawes" wrote:

> 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
>
>
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
>
Author
26 Nov 2004 8:51 PM
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





*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

AddThis Social Bookmark Button