Write Nested XML document into SQL Server tables

Joined
May 1, 2006
Messages
6
Programming Experience
3-5
Hello,

I have an xml document that I am pulling from a webservice through vb.net that has nested tables in it. I need to write each of these nested tables each to a separate Sql Server table using VB.NET.

I have the xml schema file of the webservice xml in my visual studio project, and I have had no problem writing previous xmls (writing children to a table that had a single parent) to Sql Server with code I have written in vb.net. The problem is I've never iterated through a nested xml before in vb.net and need help getting in the right direction (I have exhausted google and this forum trying to find an answer). I have done this with XPath in java before, but as I am new to vb.net, I'm a little unsure about the power of some of the classes.

For my write using xml documents with single parent-child data, here is a code snippet I've used (forgive any typos, I can't just copy and paste the source code bc it is on a confidential box, I have to type it out):

------------------------------
Dim counter As Integer
objDSXML = New Dataset
objDSDBTable = New DataSet("unit") //table in database is called 'unit'
ObjCmdBuilder = New SqlCommandBuilder

objDSXML.ReadXml(xmlFilePath)
objAdapter = New SqlDataAdapter("Select unitname, unittype from unit where 1=2, objSQLConn)
objAdapter.Fill(objDSDBTable)

For Each objDataRow In objDSXML.Tables(0).Rows
With ObjDSDBTable.Tables(0)

objDBRow = .NewRow()

For counter = 0 To numberOfColumns - 1
objDBRow(counter) = objDataRow(counter)
Next counter
.Rows.Add(objDBRow)

End With
Next

ObjCmdBuilder = New SqlCommandBuilder(objAdapter)
objAdapter.Update(objDSDTable,"unit")
------------------------------------

Using something similar to this, can someone show me code for a nested XML that can be iterated through and written to a database? If not, can someone show me a working example of how to do this?

Thanks in advance!! :)
 
Last edited:
Back
Top