PC Review


Reply
Thread Tools Rate Thread

DataTable or DataSet from XML

 
 
JohnAD
Guest
Posts: n/a
 
      29th Dec 2006
Hello NG,

Originally I posted this question on microsoft.public.xml but did not get
any reply all day so cross posting it on this NG in hope of getting some
answer -

I have a very basic understanding of XML so need some help here. I have a
XML file (structure given below). I want to change it to a DataSet or
DataTable. Basically I will be using a .Net language (do not matter which
one) and I have heard that there are lots of big support for XML in .Net.

Any pointers will be great.

Thank you very much.
Po



<?xml...
<?xml-stylesheet...

<rootNode attributes="...">
<SecondLevelRoot>
<PageTitle>I am a cool page title</PageTitle>
<Items>
<more1><![CDATA[hello]]></more1>
<more2>23423234234233223</more2>
<more3>lots of stuff....</more3>
<more4>more stuff.......</more4>
<more5>some url links...</more5>
</Items>
<Items>
.....
</Items>
<Items>
.....
</Items>
</SecondLevelRoot>
</rootNode>


 
Reply With Quote
 
 
 
 
=?Utf-8?B?WE9S?=
Guest
Posts: n/a
 
      29th Dec 2006
this is a good article

http://msdn2.microsoft.com/en-us/library/ekw4dh3f(VS.80).aspx
 
Reply With Quote
 
JohnAD
Guest
Posts: n/a
 
      29th Dec 2006
This article gives me some ideas. I was wondering if rather creating
DataTable directly we could change the node names to make it more user
friendly? Is there a way to walk through every node name and change its name
or change while reading it into a DataTable or DataSet?



"XOR" <(E-Mail Removed)> wrote in message
news:78970409-2E9F-4433-A009-(E-Mail Removed)...
> this is a good article
>
> http://msdn2.microsoft.com/en-us/library/ekw4dh3f(VS.80).aspx


 
Reply With Quote
 
=?Utf-8?B?WE9S?=
Guest
Posts: n/a
 
      29th Dec 2006
what you could do is read all the data in, then rename the columns?
 
Reply With Quote
 
JohnAD
Guest
Posts: n/a
 
      29th Dec 2006
yes that is a good point. thanks.

"XOR" <(E-Mail Removed)> wrote in message
news:67F52CEA-B59E-425E-8ED3-(E-Mail Removed)...
> what you could do is read all the data in, then rename the columns?


 
Reply With Quote
 
sloan
Guest
Posts: n/a
 
      29th Dec 2006

Ok.. a DataSet .. at is core is an xml file.
The advantage of a DataSet is that you get some MS methods for dealing with
that Xml.

There is also something called a "strong typed dataset", where you define
the schema for the xml/dataset. This is a powerful tool in DotNet.

You kinda have two options. Well, at least how I'd approach it.

1.
Define a strong typed dataset. ( Go to "Add New Item / DataSet")
You can name it whatever you want. I might call it ItemDS.

By defining a strong dataset, you can actually get to all the tables in the
dataset, all the row, and all the columns programatically.

Lets say in the ItemsDS, you create a table called "Item". And you add the
rows MoreStuff1 , MoreStuff2 (as strings)

You could then do

ItemDS ds = new ItemDS();

ItemDS.ItemRow newRow = ds.Item.NewItemRow();
newRow.MoreStuff1 = "abc";
newRow.MoreStuff2 = "def";
ds.Item.AddNewItemRow(newRow);

newRow = ds.Item.NewItemRow();
newRow.MoreStuff1 = "wxz";
newRow.MoreStuff2 = "tuv";
ds.Item.AddNewItemRow(newRow);

If you ran

Console.WriteLine (ds.GetXml()) ; //you'd get

<ItemDS>
<Item>
<MoreStuff1>abc</MoreStuff1>
<MoreStuff2>def</MoreStuff2>
</Item>
<Item>
<MoreStuff1>wxz</MoreStuff1>
<MoreStuff2>tuv</MoreStuff2>
</Item>
</ItemDS>


You'll have to play with it some......... you won't get it over night.

2.

You can create a strong typed dataset, (as above), and then do an Xml to Xml
transformation.

You would basically define an .xsl file, which is used to transform xml into
something else. Most times you change xml into HTML, but you can also
change it into another xml string.

That's alot of to go over. But its an idea. Your goal would be to create
an xml string that looked exactly like (structure wise) to

<ItemDS>
<Item>
<MoreStuff1>abc</MoreStuff1>
<MoreStuff2>def</MoreStuff2>
</Item>
<Item>
<MoreStuff1>wxz</MoreStuff1>
<MoreStuff2>tuv</MoreStuff2>
</Item>
</ItemDS>

and then you could load that up into a new ItemDS.



"JohnAD" <(E-Mail Removed)> wrote in message
news:%23TT0$(E-Mail Removed)...
> Hello NG,
>
> Originally I posted this question on microsoft.public.xml but did not get
> any reply all day so cross posting it on this NG in hope of getting some
> answer -
>
> I have a very basic understanding of XML so need some help here. I have a
> XML file (structure given below). I want to change it to a DataSet or
> DataTable. Basically I will be using a .Net language (do not matter which
> one) and I have heard that there are lots of big support for XML in .Net.
>
> Any pointers will be great.
>
> Thank you very much.
> Po
>
>
>
> <?xml...
> <?xml-stylesheet...
>
> <rootNode attributes="...">
> <SecondLevelRoot>
> <PageTitle>I am a cool page title</PageTitle>
> <Items>
> <more1><![CDATA[hello]]></more1>
> <more2>23423234234233223</more2>
> <more3>lots of stuff....</more3>
> <more4>more stuff.......</more4>
> <more5>some url links...</more5>
> </Items>
> <Items>
> .....
> </Items>
> <Items>
> .....
> </Items>
> </SecondLevelRoot>
> </rootNode>
>
>



 
Reply With Quote
 
JohnAD
Guest
Posts: n/a
 
      29th Dec 2006
Thanks sloan that is a good information. I have started working on xml books
for now



"sloan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> Ok.. a DataSet .. at is core is an xml file.
> The advantage of a DataSet is that you get some MS methods for dealing
> with
> that Xml.
>
> There is also something called a "strong typed dataset", where you define
> the schema for the xml/dataset. This is a powerful tool in DotNet.
>
> You kinda have two options. Well, at least how I'd approach it.
>
> 1.
> Define a strong typed dataset. ( Go to "Add New Item / DataSet")
> You can name it whatever you want. I might call it ItemDS.
>
> By defining a strong dataset, you can actually get to all the tables in
> the
> dataset, all the row, and all the columns programatically.
>
> Lets say in the ItemsDS, you create a table called "Item". And you add
> the
> rows MoreStuff1 , MoreStuff2 (as strings)
>
> You could then do
>
> ItemDS ds = new ItemDS();
>
> ItemDS.ItemRow newRow = ds.Item.NewItemRow();
> newRow.MoreStuff1 = "abc";
> newRow.MoreStuff2 = "def";
> ds.Item.AddNewItemRow(newRow);
>
> newRow = ds.Item.NewItemRow();
> newRow.MoreStuff1 = "wxz";
> newRow.MoreStuff2 = "tuv";
> ds.Item.AddNewItemRow(newRow);
>
> If you ran
>
> Console.WriteLine (ds.GetXml()) ; //you'd get
>
> <ItemDS>
> <Item>
> <MoreStuff1>abc</MoreStuff1>
> <MoreStuff2>def</MoreStuff2>
> </Item>
> <Item>
> <MoreStuff1>wxz</MoreStuff1>
> <MoreStuff2>tuv</MoreStuff2>
> </Item>
> </ItemDS>
>
>
> You'll have to play with it some......... you won't get it over night.
>
> 2.
>
> You can create a strong typed dataset, (as above), and then do an Xml to
> Xml
> transformation.
>
> You would basically define an .xsl file, which is used to transform xml
> into
> something else. Most times you change xml into HTML, but you can also
> change it into another xml string.
>
> That's alot of to go over. But its an idea. Your goal would be to create
> an xml string that looked exactly like (structure wise) to
>
> <ItemDS>
> <Item>
> <MoreStuff1>abc</MoreStuff1>
> <MoreStuff2>def</MoreStuff2>
> </Item>
> <Item>
> <MoreStuff1>wxz</MoreStuff1>
> <MoreStuff2>tuv</MoreStuff2>
> </Item>
> </ItemDS>
>
> and then you could load that up into a new ItemDS.
>
>
>
> "JohnAD" <(E-Mail Removed)> wrote in message
> news:%23TT0$(E-Mail Removed)...
>> Hello NG,
>>
>> Originally I posted this question on microsoft.public.xml but did not get
>> any reply all day so cross posting it on this NG in hope of getting some
>> answer -
>>
>> I have a very basic understanding of XML so need some help here. I have a
>> XML file (structure given below). I want to change it to a DataSet or
>> DataTable. Basically I will be using a .Net language (do not matter which
>> one) and I have heard that there are lots of big support for XML in .Net.
>>
>> Any pointers will be great.
>>
>> Thank you very much.
>> Po
>>
>>
>>
>> <?xml...
>> <?xml-stylesheet...
>>
>> <rootNode attributes="...">
>> <SecondLevelRoot>
>> <PageTitle>I am a cool page title</PageTitle>
>> <Items>
>> <more1><![CDATA[hello]]></more1>
>> <more2>23423234234233223</more2>
>> <more3>lots of stuff....</more3>
>> <more4>more stuff.......</more4>
>> <more5>some url links...</more5>
>> </Items>
>> <Items>
>> .....
>> </Items>
>> <Items>
>> .....
>> </Items>
>> </SecondLevelRoot>
>> </rootNode>
>>
>>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to fix A DataTable named 'Tag2' already belongs to this DataSet.(XML/Datatable) frodenekkoy@hotmail.com Microsoft Dot NET 0 8th Jul 2008 08:14 AM
Copying records from datatable to datatable in dataset tshad Microsoft C# .NET 1 24th Jun 2008 01:39 AM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 7 9th Dec 2003 02:50 PM
copying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft ADO .NET 2 31st Oct 2003 01:05 PM
Ccopying a datatable content from an untyped dataset into a table which is inside a typed dataset Nedu N Microsoft C# .NET 1 31st Oct 2003 02:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:18 PM.