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

DataSet.ReadXml and Attributes

I'm trying to figure out which column an XML attribute belongs to when
read into a dataset. Take the following XML fragment:
<FileList>
<file name="file1"></file>
<file name="file2"></file>
</FileList>

How would I get out the file name?

I have the code below so far.

Thank for any help!

--Brent

====================================
//after successfully getting a bit of XML from http

XmlTextReader xmlReader = new XmlTextReader(sr);

DataSet ds = new DataSet();

ds.ReadXml(xmlReader);

DataTable tableFiles = ds.Tables["FileList"];

for (int i = 0; i < tableFiles.Rows.Count; i++)
{
object[] fileRow = tableFiles.Rows[i].ItemArray;

//Here's where I can't seem to get the XML attribute
//What "column" is the XML "name" attribute located in?

string fileName = fileRow.GetValue(0); //<--DOES NOT WORK

}

Apr 10 '08 #1
2 8626
Brent wrote:
I'm trying to figure out which column an XML attribute belongs to when
read into a dataset. Take the following XML fragment:
<FileList>
<file name="file1"></file>
<file name="file2"></file>
</FileList>

How would I get out the file name?
If you read that XML into a DataSet then the DataSet has one table named
'file' which has one column named 'name' and two rows of data so you
could use
DataSet ds = new DataSet();
ds.ReadXml("file.xml");
DataTable file = ds.Tables["file"];
foreach (DataRow row in file.Rows)
{
Console.WriteLine(row[0]);
}
to output

file1
file2
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Apr 10 '08 #2
On Apr 10, 4:30 am, Martin Honnen <mahotr...@yahoo.dewrote:
Brent wrote:
I'm trying to figure out which column an XML attribute belongs to when
read into a dataset. Take the following XML fragment:
<FileList>
<file name="file1"></file>
<file name="file2"></file>
</FileList>
How would I get out the file name?

If you read that XML into a DataSet then the DataSet has one table named
'file' which has one column named 'name' and two rows of data so you
could use
DataSet ds = new DataSet();
ds.ReadXml("file.xml");
DataTable file = ds.Tables["file"];
foreach (DataRow row in file.Rows)
{
Console.WriteLine(row[0]);
}
to output

file1
file2

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Thank you. That did it!

--Brent
Jun 27 '08 #3

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

Similar topics

3
by: Bill C. | last post by:
Hi, I've got a simple console app that just reads an XML file into a DataSet then prints out a description of each table in the DataSet, including column names and row values for each column. ...
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...
3
by: Jeronimo Bertran | last post by:
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>...
0
by: Tim Nelson | last post by:
I've got an XML document I am loading into a dataset using ..ReadXml/.ReadXmlSchema. The dataset looks perfect and I can bind it to a datagrid and elements appear as tables and attributes appear...
2
by: ringo | last post by:
I've come accross an interesting problem populating an asp.net datagrid. I am trying to bind XML data to a datagrid as I've done in countless other applications, the only difference this time being...
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: 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: KillerJ | last post by:
I found a post about this exact issue: ...
6
by: samoore33 | last post by:
I have created a xml doc that stores dates. On the first of the year I want to upload the xml doc into a dataset and then loop through it adding one year to those dates. This is what I have...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.