473,386 Members | 1,758 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,386 software developers and data experts.

Data from XML file to Dataset

Hi All,

I need some help getting data from an XML file into a dataset. The XML file
has more data in it than I actually need. So, what I think I need to do is
to create a dataset with the tables and columns that I need, then use the
dataset.ReadXml to put the data into the tables.

So, I've created a dataset, created 3 tables, each with 2 columns. I have
three dataviews on a form linked to these tables. So far, this is what I'm
doing:

Private Sub Load_XML_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Load_XML.Click
Dim result As DialogResult = XML_Picker.ShowDialog
If result = Windows.Forms.DialogResult.OK Then
Dim fsReadXml As New System.IO.FileStream(XML_Picker.FileName,
System.IO.FileMode.Open)
Dim myXmlReader As New System.Xml.XmlTextReader(fsReadXml)
DataSet1.ReadXml(myXmlReader, XmlReadMode.IgnoreSchema)
myXmlReader.Close()
End If
End Sub

I have an XSLT file for the XML file, but I'm not sure how to use it or if I
need it to aid in getting this data into the dataset. I'm sure I'm missing
100 steps in doing this, but I don't know what they are. All of the examples
I have looked at show how to write an XML file from a dataset, then read
that XML file into a new dataset. Unfortunately, none of the samples create
a file that looks anything like the XML file I'm starting with, so I'm a bit
lost.

TIA

Lee

Nov 21 '05 #1
3 1523
Hi

To load an XML into dataset, the xml file needed to be compatible with
DataSet Schema.
That is to say the XML file's structure will be similar with the xml file
we call WriteXML on a dataset.
So we need to write to write a special XSLT to do the convert, or convert
it manually.

Alternatively, we can use the XML DOM to parse the XML node one by one and
insert them into datatables in the dataset using coding.

e.g.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(@"..\..\Test.xml");
foreach(XmlNode xn in xmlDoc.ChildNodes)
{
Debug.WriteLine(xn.Name);
foreach(XmlNode xnl in xn.ChildNodes)
Debug.WriteLine("\t"+xnl.Name);
}

Best regards,

Peter Huang
Microsoft Online Partner Support

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

Nov 21 '05 #2
at the basic level, you
0) create a DataSet object, dset
1) use the method ReadXmlSchema of the instance dset
2) create an XmlDataDocument from the dset, xdd
3) use the Load method of the xdd object
4) bind the data

here's a quick snippet:
Dim dset As New DataSet()
dset.ReadXmlSchema("mySchema.xsd")
Dim xdd as New XmlDataDocument(dset)
xdd.Load("myData.xml")
myDataGridView.DataSource = dset
myDataGridView.DataMember = "myRowName"
---
http://code.box.sk
nemo me impune lacessit
From: lgbjr


*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #3
Hi,

For those the ones who search this newsgroup and use VBNet the sample from
Peter translated

\\\
Dim XmlDoc as New XmlDocument
xmlDoc.Load("...\..\Test.xml")
For each xn as XmlNode in xmlDoc.ChildNodes
Debug.WriteLine(xn.Name)
for each xnl as XMLNode in xn.ChildNodes
Debug.WriteLine(VBTab & xnl.Name)
next for
next for
///

Never mind Peter I was just

:-))))))

Cor
Nov 21 '05 #4

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

Similar topics

4
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have...
7
by: Sharon | last post by:
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...
1
by: Angus Lepper | last post by:
I'm writing a stock ticker for a stock market simulation, and can load the data into the xmlreader in the first place, but can't figure out how to refresh/update the data in it. Any ideas? Code:...
9
by: David Harris | last post by:
Ok, so I'm semi-new to .NET, having done everything manually with SQL code back in VB6. So before I program this up completely manually again, I thought I'd ask for better ways to think through...
4
by: michael sorens | last post by:
I have successfully bound an XmlDocument to a DataGridView but all fields seem to be strings. I want to retrofit appropriate datatypes on some of the fields. Let me take this in 2 parts. Part...
0
by: David Mayerovitch | last post by:
As an exercise in learning Visual Basic 2005, I am putting together a simple XML editor. I place on the form the objects DataGridView1 and DataSet1. ' Read an XML file into DataSet1:...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
4
by: Rick | last post by:
I've moved code from a stage machine to the production machine, exact same code works fine on the stage machine, they are both windows 2003 servers, I'm getting a "Cannot generate SSPI context"...
5
by: Lucvdv | last post by:
This would better be described by 'serialization' than 'interop', but I didn't find a newsgroup that seems closer on topic. The problem in a few words: I save data with DataSet.WriteXML, but I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...

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.