473,418 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

How to populate a DataSet schema with data from and XML string?

I have successfully loaded a DataSet object with a XML schema (XSD).

Now I wish to populate the tables that was created in the DataSet.
I have an XML file/string that contain all the needed data in the same
format as the XSD (the XML file/string was created using this same schema).
The XML file/string may contain data for a single table or for several
tables at once.

The question is:

How do populate a table in the DataSet using the data from an XML
file/string in the most easiest way?
When I say easiest I mean without parsing the XML node by node and
converting the node value to the specific row member value in the table in
the DataSet.
It sound very reasonable to expect for such a function that takes an XML
data from an XML string/file and populate a schema using it.
---------
Thanks
Sharon G.
Nov 17 '05 #1
7 6203
Hi Sharon,

Welcome to MSDN newsgroup.
As for the populating a DataSet's data with a existing Xml file which
contains the serilized table datas, if the xml file's content is exactly
match to the DataSet's schema or is direclty generated through
DataSet.WriteXml method, we can just use DataSet.ReadXml method to read the
data back to dataset instance from a xml file(or xml string, xml file
Stream....). Also the DataSet.ReadXmlSchema method can also help to load xml
schema from external file or stream. Here is their msdn reference:

#DataSet.ReadXml Method
http://msdn.microsoft.com/library/en...asp?frame=true

#DataSet.ReadXmlSchema Method
http://msdn.microsoft.com/library/en...asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no rights.)

"Sharon" wrote:
I have successfully loaded a DataSet object with a XML schema (XSD).

Now I wish to populate the tables that was created in the DataSet.
I have an XML file/string that contain all the needed data in the same
format as the XSD (the XML file/string was created using this same schema).
The XML file/string may contain data for a single table or for several
tables at once.

The question is:

How do populate a table in the DataSet using the data from an XML
file/string in the most easiest way?
When I say easiest I mean without parsing the XML node by node and
converting the node value to the specific row member value in the table in
the DataSet.
It sound very reasonable to expect for such a function that takes an XML
data from an XML string/file and populate a schema using it.
---------
Thanks
Sharon G.

Nov 17 '05 #2
Hi Sharon,

Welcome to MSDN newsgroup.
As for the populating a DataSet's data with a existing Xml file which
contains the serilized table datas, if the xml file's content is exactly
match to the DataSet's schema or is direclty generated through
DataSet.WriteXml method, we can just use DataSet.ReadXml method to read the
data back to dataset instance from a xml file(or xml string, xml file
Stream....). Also the DataSet.ReadXmlSchema method can also help to load xml
schema from external file or stream. Here is their msdn reference:

#DataSet.ReadXml Method
http://msdn.microsoft.com/library/en...asp?frame=true

#DataSet.ReadXmlSchema Method
http://msdn.microsoft.com/library/en...asp?frame=true

Hope helps. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no rights.)

"Sharon" wrote:
I have successfully loaded a DataSet object with a XML schema (XSD).

Now I wish to populate the tables that was created in the DataSet.
I have an XML file/string that contain all the needed data in the same
format as the XSD (the XML file/string was created using this same schema).
The XML file/string may contain data for a single table or for several
tables at once.

The question is:

How do populate a table in the DataSet using the data from an XML
file/string in the most easiest way?
When I say easiest I mean without parsing the XML node by node and
converting the node value to the specific row member value in the table in
the DataSet.
It sound very reasonable to expect for such a function that takes an XML
data from an XML string/file and populate a schema using it.
---------
Thanks
Sharon G.

Nov 17 '05 #3
Hi Steven,

The ReadXml is not in my case.
Allow me to clarify the problem.

I have a DataSet loaded with an xml schema. So now the dataset contains some
tables and relations.
I need to supply a function that receives an xml string containing one or
more entries in some table like:
<Defect>
<ID>0</ID>
<Type>hole</Type>
<Sevirity>1</Sevirity>
<XCoordinate>20</XCoordinate>
<YCoordinate>300</YCoordinate>
<Deleted>false</Deleted>
<DefectUI>
<Shape>Circle</Shape>
<RedColor>0</RedColor>
<GreenColor>100</GreenColor>
<BlueColor>255</BlueColor>
</DefectUI>
</Defect>

The Defect table may contain more sub tables and the also the Defect table
may be a sub table of another table.

Is there a straight forward way to fill the dataset with the values given by
the string xml like the shown above?
--------
Thanks
Sharon
Nov 17 '05 #4
Hi Steven,

The ReadXml is not in my case.
Allow me to clarify the problem.

I have a DataSet loaded with an xml schema. So now the dataset contains some
tables and relations.
I need to supply a function that receives an xml string containing one or
more entries in some table like:
<Defect>
<ID>0</ID>
<Type>hole</Type>
<Sevirity>1</Sevirity>
<XCoordinate>20</XCoordinate>
<YCoordinate>300</YCoordinate>
<Deleted>false</Deleted>
<DefectUI>
<Shape>Circle</Shape>
<RedColor>0</RedColor>
<GreenColor>100</GreenColor>
<BlueColor>255</BlueColor>
</DefectUI>
</Defect>

The Defect table may contain more sub tables and the also the Defect table
may be a sub table of another table.

Is there a straight forward way to fill the dataset with the values given by
the string xml like the shown above?
--------
Thanks
Sharon
Nov 17 '05 #5
Hi Sharon,

Thanks for your response.
So based on your further description, my understanding on your problem is
that:

You have create a DataSet instance and populate its schema structure
through a schema. And now you may have some other strings(more than one),
and each string may contain data of of some certain Tables in the DataSet's
structure. You'd like to write a function which can help return DataRow of
Table from those strings and add into the Dataset, yes?

If so, I think we can consider the following means;

If the xml data in the string is exactly conform to the schema, we can
create another instance of the DataSet (which has populated its structure
with the same schema). After that, you can use this DataSet instance to
import Table data from those xml strings. We can use the
System.IO.StringReader to construct a reader from string, and use
DataSet.ReadXml
to populate data from that string. After that , you can try using
DataSet.Merge to merge data between this helper dataset and your original
dataset. Or you can also manually navigate into certain DataTable and use
DataTable.ImportRow to copy Row between datatable. Currently this is the
most considerable means I've found.

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: How to populate a DataSet schema with data from and XML
string
| thread-index: AcWuwR64K2xiQkONSf2Ev+JwhaOfSw==
| X-WBNR-Posting-Host: 199.203.93.141
| From: =?Utf-8?B?U2hhcm9u?= <Sh*****@newsgroups.nospam>
| References: <75**********************************@microsoft.co m>
<E2**********************************@microsoft.co m>
| Subject: RE: How to populate a DataSet schema with data from and XML
string
| Date: Wed, 31 Aug 2005 23:48:11 -0700
| Lines: 34
| Message-ID: <8B**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.languages.csharp:119645
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Steven,
|
| The ReadXml is not in my case.
| Allow me to clarify the problem.
|
| I have a DataSet loaded with an xml schema. So now the dataset contains
some
| tables and relations.
| I need to supply a function that receives an xml string containing one or
| more entries in some table like:
| <Defect>
| <ID>0</ID>
| <Type>hole</Type>
| <Sevirity>1</Sevirity>
| <XCoordinate>20</XCoordinate>
| <YCoordinate>300</YCoordinate>
| <Deleted>false</Deleted>
| <DefectUI>
| <Shape>Circle</Shape>
| <RedColor>0</RedColor>
| <GreenColor>100</GreenColor>
| <BlueColor>255</BlueColor>
| </DefectUI>
| </Defect>
|
| The Defect table may contain more sub tables and the also the Defect
table
| may be a sub table of another table.
|
| Is there a straight forward way to fill the dataset with the values given
by
| the string xml like the shown above?
|
|
| --------
| Thanks
| Sharon
|

Nov 17 '05 #6
Hi Steve,

Your suggestion will work, but the creation of a DataSet each time the API
function is called us very expensive. You can read about it at
http://www.codeproject.com/csharp/TypedDSProxy.asp

I can hold only one more DataSet for this purpose but I still think it’s an
expensive solution.

I simply thought that a function like that, that just take an XML containing
the table/row values and put them in the already built table/row exist.
I guess I was mistaken.

So I made one on my own by iterating on the XML nodes and setting each value
in the DataSet accordingly.
---------
Thanks
Sharon
Nov 17 '05 #7
Thanks for your response Sharon,

Yes, building a DataSet will have much performance cost so my original
thought is also as you mentioned using a SINGLETON pattern to host a single
Helper dataset instance to do the work. Anyway, if you really feel high
peformance concerns on this, I think your current choice on manually loop
the XML doc will work better.

Thanks & Regards,

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Thread-Topic: How to populate a DataSet schema with data from and XML
string
| thread-index: AcWxIOyCr2ZF77nqTk2KwNpGi0XICw==
| X-WBNR-Posting-Host: 199.203.93.141
| From: =?Utf-8?B?U2hhcm9u?= <Sh*****@newsgroups.nospam>
| References: <75**********************************@microsoft.co m>
<E2**********************************@microsoft.co m>
<8B**********************************@microsoft.co m>
<qQ**************@TK2MSFTNGXA01.phx.gbl>
| Subject: RE: How to populate a DataSet schema with data from and XML
string
| Date: Sun, 4 Sep 2005 00:19:01 -0700
| Lines: 20
| Message-ID: <BC**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 8bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.languages.csharp:120158
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hi Steve,
|
| Your suggestion will work, but the creation of a DataSet each time the
API
| function is called us very expensive. You can read about it at
| http://www.codeproject.com/csharp/TypedDSProxy.asp
|
| I can hold only one more DataSet for this purpose but I still think it’
s an
| expensive solution.
|
| I simply thought that a function like that, that just take an XML
containing
| the table/row values and put them in the already built table/row exist.
| I guess I was mistaken.
|
| So I made one on my own by iterating on the XML nodes and setting each
value
| in the DataSet accordingly.
|
|
| ---------
| Thanks
| Sharon
|

Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Kennedy | last post by:
How do create a dataset from scratch based on an XML schema. This will not be filled by a dataadapter. It will be a dataset which I add rows to and then save as an XML file. All the example depend...
1
by: Tarun Upadhyay | last post by:
I am trying to read the standard UDDI schema using a DataSet. however, it always chokes with error. Here are the full details: Schema used: http://uddi.org/schema/uddi_v3.xsd C# (.NET) calls...
2
by: Goldsworth_Systems | last post by:
I have a string containing valid XML. How do I populate a dataset based on the string, without reference to an XML schema or writing the XML to file and reading it back in again?
0
by: Thaddeus | last post by:
//Author: //Thaddeus Jacobs, MCP //Kinematic Automation, Inc. //mailto:tjacobs@kinematic.com // //Description: //convert ADO .NET dataset to ADO 2.5 2.6 2.7 recordset and v/v //DataSet to...
3
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different...
22
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
12
by: Whoever | last post by:
Hi, I'm trying to return an XmlDocument or XmlNode converted from a typed dataset. public XmlNode whatever() { MyTypedDataSet ds = new MyTypedDataSet(); return new XmlDataDocument(ds); }
0
by: c.w.browne | last post by:
Hi, Ive had a bit of a look around for other people with this problem and cant find anything that solves it in my case, so I'm afraid im going to have to bother you all with a post of my own. ...
1
by: Angel \Java\ Lopez | last post by:
Hi people! I'm running a Visual Studio 2005, Professional, on Windows XP Professional. I've found a little big problem, reading a DataSet. If I try: ds.ReadXml("c:\data.xml") it raises...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.