472,368 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,368 software developers and data experts.

loading Dataset from XML - urgent!

P K
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
dataset.tables("error").readXML = "<xml><r1></r1></xml>"
How can this be done???
Feb 20 '06 #1
3 2178
Dim ds As New DataSet
'load the first table from an xml file
ds.InferXmlSchema(Server.MapPath("xmlfile1.xml"), Nothing)
ds.ReadXml(Server.MapPath("xmlfile1.xml"))
'load another table from an xml file
ds.InferXmlSchema(Server.MapPath("xmlfile2.xml"), Nothing)
ds.ReadXml(Server.MapPath("xmlfile2.xml"))
'databind one datagrid to the first table
datagrid1.DataSource = ds.Tables(0)
datagrid1.DataBind()
'databind another datagrid to the second table
datagrid2.DataSource = ds.Tables(1)
datagrid2.DataBind()
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
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
dataset.tables("error").readXML = "<xml><r1></r1></xml>"
How can this be done???

Feb 21 '06 #2
P K
Phillip,

I cannot do what you say, cosI already have a dataset with a table in it.
Now I need to add a second table to it using an XML Dom object.
My XML does not reside in a file. It is in an XML DOM object.

So the goal is to add a new table to an existing dataset and the new
datatable should be loaded using an XML DOM object.

thanks
PK

"Phillip Williams" wrote:
Dim ds As New DataSet
'load the first table from an xml file
ds.InferXmlSchema(Server.MapPath("xmlfile1.xml"), Nothing)
ds.ReadXml(Server.MapPath("xmlfile1.xml"))
'load another table from an xml file
ds.InferXmlSchema(Server.MapPath("xmlfile2.xml"), Nothing)
ds.ReadXml(Server.MapPath("xmlfile2.xml"))
'databind one datagrid to the first table
datagrid1.DataSource = ds.Tables(0)
datagrid1.DataBind()
'databind another datagrid to the second table
datagrid2.DataSource = ds.Tables(1)
datagrid2.DataBind()
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
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
dataset.tables("error").readXML = "<xml><r1></r1></xml>"
How can this be done???

Feb 21 '06 #3
Even though your XmlDocument is in memory you can still write it to a file
and load it much faster than if you were to compose a new DataTable out of
it.

But I will give you both solutions anyways:

1- to create a datatable from your xmlDoc:

Dim xmlDoc As New XmlDocument
'let's assume that you have an xml document that looks like this:
xmlDoc.LoadXml("<?xml version='1.0' encoding='utf-8'
?><NewDataSet><record><field name='column1'>1.1</field><field
name='column2'>1.2</field><field
name='column3'>1.3</field></record><record><field
name='column1'>2.1</field><field name='column2'>2.2</field><field
name='column3'>2.3</field></record><record><field
name='column1'>3.1</field><field name='column2'>3.2</field><field
name='column3'>3.3</field></record></NewDataSet>")

'get the root element of the xml
Dim root As XmlElement = xmlDoc.DocumentElement
'create an XPathNavigator
Dim nav As XPath.XPathNavigator = root.CreateNavigator()
'create the table definition
Dim tbl As New DataTable
Dim fieldNodes As XPath.XPathNodeIterator = nav.Select("//field")
While fieldNodes.MoveNext
Dim strFieldName As String =
fieldNodes.Current.GetAttribute("name", "")
If Not (tbl.Columns.Contains(strFieldName)) Then
tbl.Columns.Add(New DataColumn(strFieldName))
End If
End While
Dim recordNodes As XPath.XPathNodeIterator =
nav.SelectChildren(XPath.XPathNodeType.Element)
While recordNodes.MoveNext
Dim dr As DataRow = tbl.NewRow()
fieldNodes =
recordNodes.Current.SelectChildren(XPath.XPathNode Type.Element)
While fieldNodes.MoveNext
Dim strFieldName As String =
fieldNodes.Current.GetAttribute("name", "")
dr(strFieldName) = fieldNodes.Current.Value
End While
tbl.Rows.Add(dr)
End While
'rename the imported table to whichever name you want
tbl.TableName = "Errors"
ds.Tables.Add(tbl)

2- to save the xmlDoc to a disk file then retrieve it in the existing DataSet:

Dim xmlDataDoc As New XmlDataDocument
xmlDataDoc.LoadXml(xmlDoc.OuterXml)
'You need to give the ASPNET account write/modify access to this
folder
Dim w As New XmlTextWriter(Server.MapPath("App_Data\test1.xml") ,
Nothing)
xmlDataDoc.WriteTo(w)
w.Close()

ds.ReadXmlSchema(Server.MapPath("App_Data\test1.xm l"))
ds.ReadXml(Server.MapPath("App_Data\test1.xml"))
'rename the imported table to whichever name you want
ds.Tables(ds.Tables.Count - 1).TableName = "Errors"

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
Phillip,

I cannot do what you say, cosI already have a dataset with a table in it.
Now I need to add a second table to it using an XML Dom object.
My XML does not reside in a file. It is in an XML DOM object.

So the goal is to add a new table to an existing dataset and the new
datatable should be loaded using an XML DOM object.

thanks
PK

"Phillip Williams" wrote:
Dim ds As New DataSet
'load the first table from an xml file
ds.InferXmlSchema(Server.MapPath("xmlfile1.xml"), Nothing)
ds.ReadXml(Server.MapPath("xmlfile1.xml"))
'load another table from an xml file
ds.InferXmlSchema(Server.MapPath("xmlfile2.xml"), Nothing)
ds.ReadXml(Server.MapPath("xmlfile2.xml"))
'databind one datagrid to the first table
datagrid1.DataSource = ds.Tables(0)
datagrid1.DataBind()
'databind another datagrid to the second table
datagrid2.DataSource = ds.Tables(1)
datagrid2.DataBind()
--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"P K" wrote:
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
dataset.tables("error").readXML = "<xml><r1></r1></xml>"
How can this be done???

Feb 22 '06 #4

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

Similar topics

2
by: Patrick J. Schouten | last post by:
I am trying to transfor an XML document prior to loading into a Dataset. My problem stems from the known bug in Visual Studio that prevents loading a well formed XML because of duplicate child...
4
by: RdS | last post by:
hello, When I create a form that ties to dataset of table with only 20 records in it I understand that all 20 records are copied to my local computers memory for manipulation. Then if rows were...
13
by: Maxwell2006 | last post by:
Hi, We are having a debate over using DataSet as return value type for web services. The problem is that we don't know whether Java applications can use DataSet
7
by: SteveT | last post by:
Can someone point me in the right direction? Somewhere I read that you reference a strongly typed dataset as if it were a class structure. For example, <SomeTests> <TestsGroups> <Group>...
7
by: koonda | last post by:
Hi guys, I am trying to create a web interface in C# using ASP.NET. The database being used is SQL Server. I have some problems loading the tables in the datalist controls. When I run the program...
1
by: | last post by:
I'm querying Index Server to return search results, both regular properties and some custom properties I've created. Index Server has this preference for thinking about information as strings...
0
by: Chris | last post by:
Hello, I have a problem with re-loading datasets. As a simple example, if I have an SQL table of addresses comprising active and inactive addresss, I wish to load either sub-set by clicking on...
7
by: =?Utf-8?B?TWF4R3J1dmVu?= | last post by:
I have a DLL that implements the Business and Data Layers for a number of different websites. That DLL uses a Strongly Typed DataSet to interface to the Data Source which is SQL Server. There...
3
by: cj2 | last post by:
I can't remember and can't find my notes anywhere. There were a couple of commands that when used with I think the data adapter that allowed for faster reading or writing of tables. I think one...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

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.