473,666 Members | 2,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.EventArg s) Handles Load_XML.Click
Dim result As DialogResult = XML_Picker.Show Dialog
If result = Windows.Forms.D ialogResult.OK Then
Dim fsReadXml As New System.IO.FileS tream(XML_Picke r.FileName,
System.IO.FileM ode.Open)
Dim myXmlReader As New System.Xml.XmlT extReader(fsRea dXml)
DataSet1.ReadXm l(myXmlReader, XmlReadMode.Ign oreSchema)
myXmlReader.Clo se()
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 1541
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.ChildNod es)
{
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.ReadXmlSch ema("mySchema.x sd")
Dim xdd as New XmlDataDocument (dset)
xdd.Load("myDat a.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.ChildNod es
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
555
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 no way of knowing what the tables are, or what they contain. I am currently using the Dataset.WriteXML method passing an XMLWriter.
7
6221
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 in the same format as the XSD (the XML file/string was created using this same schema). The XML file/string may contain data for a single table or for several tables at once. The question is:
1
2304
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: Public Class Form1 Inherits System.Windows.Forms.Form
9
1833
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 this problem. We have several client machines, and a central data warehousing server. Each machine may contain hundreds of surveys, and they all are sent to the central server. Only they can never be networked together, forcing us to use files. I...
4
16729
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 I: I found the ValueType field, leading me to believe that I could say dataGridView.Columns.ValueType = typeof(Double); dataGridView.Columns.ValueType = typeof(Integer); etc.
0
1797
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: DataSet1.ReadXml("BIRDS.XML") ' Bind the DataGridView to the DataSet: DataGridView1.DataSource = DataSet1
12
6208
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 datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my code: //Function For Importing Data From CSV File public DataSet ConnectCSV(string filetable)
4
4146
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" error, there are other sites on this server that access the same database. IIS is the same, permissions to the database are correct. Any suggestions? Error:
5
3591
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 get different data back when I read it later with DataSet.ReadXml. More detail:
0
8449
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
8876
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...
1
8556
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
8642
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
6198
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
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4371
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2774
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.