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

Import XML file into dataset

Hello all together,

I have a little problem importing the following xml file into a dataset.

<?xml version="1.0" standalone="yes"?>
<logfile version = "0.1.001" >
<log date = "01.01.2005" time = "12:01:59" username = "Mueller" level =
"Info" message = "2">
<data order="1" caption="Original Value">60</data>
<data order="2" caption="Changed Value">80</data>
</log>
</logfile>

If I load the xml file in Visual Studio and looks at the data page I see 3
data tables.

1. logfile
2. log
3. data

If I choose the table 'log' it shows all information which are stored in the
tag 'log'.
Now I can expand a datarow and gets a link 'log data'.
If I click this link I get a new table with the information stored in the
tags 'data'.

That's fine, but how can I get access to the information within my code?
Hope you understand my problem and can help me.

Best regards
Thomas
Nov 16 '05 #1
11 13440
Thomas,

And XML dataset contains only elements. You have an XML document.
That you can only import in a dataset by reading it looping while using the
xmlnodereader to get attribute by attribute to set those in the dataset
elements (items).

I hope this gives an idea

Cor
Nov 16 '05 #2
Hello Cor,

Hmm Visual Studio displays the XML file in a dataset with 2 layers (don't
know how to describe it better).
The first layer is a table which contains all information from the tag
'log'.
That means I have a table which contains rows like this one (according to my
example):

01.01.2005 12:01:59 Mueller Info 2

This rows have a plus, so I can expand it.
If I expand the row, I get a link to the second layer or better a second
table which contains the information of the tag 'data'.
The problem is that I don't have access to the second layer within my code.
I get the first layer (table) if I use the readXml-method of the dataset but
not the second layer (table).

Hope you understand what I mean.

Best regards
Thomas
Nov 16 '05 #3
Thomas,

You can read it as dataset.

To show it, you can use the designer or this simple method.
\\\
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml("XMLFile1.xml");
this.dataGrid1.DataSource = ds;
this.dataGrid1.Expand(-1);
///

I hope this helps?

Cor
Nov 16 '05 #4
Hello Cor,

that is not my problem.
I know that the designer shows me the XML file as a dataset.
You can see in my posting sent 24.02.2005 12:04, what my problem with this
representation is.
I need to get access to the secon layer and the information stored in the
'data' tag.

Best regards
Thomas
Nov 16 '05 #5
Thomas,

That was why I showed this sample, when I add this
\\\
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml("XMLFile1.xml");
this.dataGrid1.DataSource = ds;
this.dataGrid1.Expand(-1);
this.textBox1.DataBindings.Add("Text",ds.Tables[1],"username");
///

Than I see "Mueller" in the textbox on the form.

It has an other effect that I don't like however it is because of this
sample because the field name what is than

ds.Tables["log"]["username"]

I was expecting you understood that.

I hope this helps?

Cor
Nov 16 '05 #6
Hello Cor,

ok so I get access to the information stored in the tag 'log'.
I understood your example, but I don't get access to the information stored
in the tag 'data', because this information are stored in another table I
think or a table with a filter?!?
That is my main problem.

Thanks already for your time.

Best regards
Thomas
Nov 16 '05 #7
Thomas,

Did you try my sample,

I get with this in the datagrid exactly what I expected.
(I see now that my too quick typed datafield was wrong however the method
stays the same)
{
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml("XMLFile1.xml");
ds.Tables["data"].Rows[0]["caption"] = "Hello I am there";
this.dataGrid1.DataSource = ds;
this.dataGrid1.Expand(-1);
}

I hope this helps?

Cor
Nov 16 '05 #8
Hi Cor,

yes, your example shows me the XML file in a dataset like the designer does.
If I access the table 'data' with this code line:

ds.Tables["data"].Rows[0]["caption"] = "Hello I am there";

it works fine, but I don't have a relation to the related datarow in the
table 'log', did I?
The dataset in your example also shows me the link to the table 'data' if I
expand a datarow in the table 'log'.
But I can't access this filtered view of the table 'data'.

Best regards
Thomas

Nov 16 '05 #9
Hi Cor,

yes, your example shows me the XML file in a dataset like the designer does.
If I access the table 'data' with this code line:

ds.Tables["data"].Rows[0]["caption"] = "Hello I am there";

it works fine, but I don't have a relation to the related datarow in the
table 'log', did I?
The dataset in your example also shows me the link to the table 'data' if I
expand a datarow in the table 'log'.
But I can't access this filtered view of the table 'data'.

Best regards
Thomas
Nov 16 '05 #10
Thomas,

You mean this one, that is just playing with the relations.
\\\\
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml("XMLFile1.xml");
ds.Tables["data"].Rows[0]["caption"] = "Hello I am there";
ds.Tables["log"].ChildRelations[0].ChildTable.Rows[1]["caption"] = "I too";
this.dataGrid1.DataSource = ds;
this.dataGrid1.Expand(-1);
///

I hope it becomes clearer?

Cor
Nov 16 '05 #11
Hi Cor,

many thanks to you.

The following sample code delivers me the needed information:

System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml("log_2-2005.xml");

foreach (DataRow dr in ds.Tables["log"].Rows)
{
System.Windows.Forms.MessageBox.Show(dr["level"].ToString() + ", " +
dr["message"].ToString());
DataRow[] childs = dr.GetChildRows("log_data");
foreach(DataRow dr2 in childs)
{
System.Windows.Forms.MessageBox.Show(dr2["data_text"].ToString());
}
}

Thanks for the spent time in my problem.
I think now I understand the dataset much better.

Best regards
Thomas
Nov 16 '05 #12

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

Similar topics

2
by: Eric Caron | last post by:
Hi I try to import file in a dataset. How I can do this ?
1
by: Ed Bacon | last post by:
I am trying to produce a generic "audit report" for various transactions in our application. Each transaction type defines a document (and has an associated schema). When a transaction leads to a...
0
by: Kiran | last post by:
Hi, Does some one here know how to trigger export(bulk/non bulk) and use bulk import without having to manually edit the Xsd file before import. BTW I am assuming that XML is the correct choice...
2
by: Ghost | last post by:
Hello. What is the optimal way to manualy import/export data from/to XML file to/form my DataSet? What I wnat: 1. To add some data (records) from XML file to may dataset. 2.. To add some...
3
by: Schultz | last post by:
I would like to know if it is possible to import data from MS Excel 2000 to a dataset using asp.net. The excel file would need to be uploaded to the server from a web page first, before the loaded...
7
by: Joe Fallon | last post by:
I am importing a delimited ASCII text file into a dataset using OLEDB. I set up the connection and dataadapter and then fill the dataset. It works - sort of. It turns out that some of my data is...
4
by: BostonNole | last post by:
I am looking for suggestions on the most efficient way to import 7 different fixed width files into a DataSet. Not all at the same time. One file at a time, but the format could change from file...
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
1
by: The_Fakir_42 | last post by:
Hi, I have a very tricky problem... I import an XLS file from my asp web application; this xls file contains lots of single-cell named areas. Usually, I know how to get them, this way : '...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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.