473,757 Members | 7,200 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ReadX ml(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.MoveToN extAttribute())
{
}

and then I try to use

myDataset.XmlRe ad(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(r eader.GetRemain der());
myDataset.XmlRe ad(readerDatase t);

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 6601
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
misunderstandin g, please feel free to let me know.

In this case, I think you can try to use ReadStartElemen t 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.ReadStartElem ent("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
4831
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 should be created in the dataset with the provided xml. However, after the ReadXML statement there are no rows in the DataSet.Tables ? IS there something I'm missing? I can assure you that the schema is correct, since it was originally created with...
8
5686
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 I convert data type of one of the column to integer and then I use the Dataset.ReadXml function and pass the same file to it. This works on my machine, but when I run it on a .NET 2.0 machine it thows an exception with message "Input string was...
1
3156
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 may encounter slow performance. To ensure best performance for ReadXml, on a large file, call the DataTable.BeginLoadData method for each table in the DataSet, then call ReadXml. Finally, call DataTable.EndLoadData for each table in the DataSet as...
4
1307
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
23770
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 DataSetForXML.ReadXml(XMLDataToString) but I received error messages. Does anyone know how to do this without creating a file (disk copy) of this XML data? Thanks for your help. Marc
3
2277
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 table is a XMLDoc. So I have the XML in a XMLDoc and I need to create a table in the dataset which would read xml from the XMLDoc . So in essence I need something like
11
3948
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
5021
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 XML file. I want to use this same dataset (in another instance of the application) and the DiffGram to display the changes in the DataGridView as they existed after the user made his/her change. In English:
2
5853
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 to create a DataSet object from an XSD file by using XMLDataDocument class.
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10072
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.