473,396 Members | 2,024 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,396 software developers and data experts.

DataSet.ReadXml with an extract from an xml file

Hi,

I have an xml file that encapsulates a dataset definition within a set
of tags (<dataset>)... here is an example

<?xml version="1.0" encoding="utf-16"?>
<dataset>
<MyTable>
<Field1>100</Field1>
<Field2>200</Field2>
</MyTable>
</dataset>

I first use an XmlTextReader to read the root tag and if it is the
<dataset> tag then I use DataSet.XmlRead to read into the dataset.
myDataset.ReadXml(reader);

The above example works fine and creates a single table named MyTable in
the dataset. However, if I want to add an attribute to the dataset tag:

<?xml version="1.0" encoding="utf-16"?>
<dataset myAttribute = "1">
<MyTable>
<Field1>100</Field1>
<Field2>200</Field2>
</MyTable>
</dataset>
I first use an XmlTextReader to read the root tag and if it is the
<dataset> tag then I read the attributes:

while (reader.MoveToNextAttribute())
{
}

and then I try to use

myDataset.XmlRead(reader);

The dataset is created with two tables, one for the dataset tag and the
other for MyTable.

I tried using GetRemainder afeter reading the attributes and using this
reader to fill the dataset:

XmlTextReader readerDataset = new XmlTextReader(reader.GetRemainder());
myDataset.XmlRead(readerDataset);

but this produces a parsing error because of the closing <dataset> tag.

Is there a simple way to extract the dataset xml to use in
DataSet.XmlRead?

Thanks,

Jeronimo Bertran
Nov 12 '05 #1
3 6576
Hi Jeronimo,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to ignore the attributes in
the dataset table and put the inner xml to a DataTable. If there is any
misunderstanding, please feel free to let me know.

In this case, I think you can try to use ReadStartElement to advance to the
next node and read the whole table into DataSet. Here is a code snippet.
HTH.

XmlTextReader r = new XmlTextReader(@"c:\b.xml");
r.MoveToContent();
r.ReadStartElement("dataset");
DataSet ds = new DataSet();
ds.ReadXml(r);
this.dataGrid1.DataSource = ds;

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #2
Thanks.... that worked!

Jeronimo
Nov 12 '05 #3
You're welcome, Jeronimo.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #4

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

Similar topics

1
by: Jeffrey A. Voigt | last post by:
I'm having trouble loading some xml data into a dataset via the ReadXML call. I'm loading into the dataset an xml schema prior to the ReadXML call. I see that there IS in fact, 3 records that...
8
by: Nikhilesh Mehendale | last post by:
I have written a web service in C#, .NET 1.1 which reads a XML file into a dataset. This is just a plain XML file. First I use the Dataset.ReadXmlScheme function and pass the XML file to it. Then...
1
by: kids_pro | last post by:
I had come across a code block from Loading a DataSet from XML (.NET Framework Developer's Guide) ---------------------------------------- NOte If you call ReadXML to load a very large file, you...
4
by: Shapper | last post by:
Hello, I have a XML file that includes the node <item>: .... <title>...</title> <url>...</url> <item> <title>title 01</title> <description>description 01</description> </item>
12
by: Marc | last post by:
I have used XMLDataToString = DataSetForXML.GetXml() to get an XML string from a dataset. I am looking for a way to create a dataset from this XML string. I tried...
3
by: P K | last post by:
Hello, I have a dataset which is already loaded with data in one table. so dataset.tables("data") exists and has data. Now, I have to add another table to the dataset. The source for this...
11
by: MurdockSE | last post by:
Greetings. My Situation: // I have an .xml file that I am reading into a dataset in the following code - DataSet ds = new DataSet("MyDataset"); ds.ReadXml(@"c:\data\"+cmyxmlfilename);
1
by: GoogleGroups | last post by:
It seems like this should be easy, but it has proven to be quite painful. I have an existing dataset, which I used the GetChanges and WriteXML functions upon to write out a DiffGram to a local...
2
by: ERingmae | last post by:
Hi, The environment is .NET 2.0, the language is C# and the problem is reading XSD file with xs:redefine section correctly to a XMLDataDocument.DataSet. What I am trying to do: I am trying...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.