Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Building Parent-Child Relationship in XML

From: DeanHinson@-----------.---------.---
To: NULL
Date: 12/5/2005 8:23:00 AM
Hello,

I am a newbiw to XML and have been tasked to generate some data dumps into 
an XML file.  The file I'm dealing with contains material parent-child 
relationship and I created a stored procedure to explode the relationship.  
Using the stored procedure in a VB script, I thought it would be easy to go 
down each level using a OO programming style.  However, I keep getting this 
error:
  msxml4.dll: Inserting a Node or its ancestor under itself is not allowed.

Since I already exploded the parent-child relationship out, I didn't think 
this would be an issue.  I have enclosed my script below and appreciate any 
assistance received.

Option Explicit

'-----------------------------------------------------------------------------------'
' Declare Global Variables                                                   
       '
'-----------------------------------------------------------------------------------'
Dim objADORS
Dim objXMLDoc

Dim intLevel

Dim nodeTemp, nodeRoot, nodeAttribute
Dim nodeLevel, nodeSequence, nodeMaterial

'Create ADO and MSXML DOMDocument Objects
Set objADORS  = CreateObject("ADODB.Recordset")
Set objXMLDoc = CreateObject("MSXML2.DOMDocument.4.0")

'Run the stored procedure and load the Recordset
objADORS.Open "EXEC sp_PSPSP100_EXPAND_QUERY '0265202330001'", _
	"Provider=sqloledb;Data Source=sbdmssp20\vsql2;Initial 
Catalog=db_927;Integrated Security=SSPI"

'Prepare the XML Document
objXMLDoc.loadXML "<Product_Structure />"

'Output Assembly Information
objADORS.moveFirst

Set nodeRoot = objXMLDoc.documentElement

Set nodeTemp = objXMLDoc.createElement("Assembly")
Set nodeAttribute = objXMLDoc.CreateAttribute("ID")
nodeAttribute.Value = objADORS.Fields("MATERIAL").Value
nodeTemp.SetAttributeNode(nodeAttribute)
nodeTemp.nodeTypedValue = objADORS.Fields("DESCP").Value
nodeRoot.appendChild nodeTemp

objADORS.moveNext

intLevel = 0
		
'For each record in the Recordset
While Not objADORS.EOF
	intLevel = CInt(objADORS.Fields("LEVEL").Value)

	Call ProcessChildren(nodeTemp, objADORS, intLevel)

Wend

objADORS.Close
Set objADORS = Nothing

'Save the created XML document
objXMLDoc.Save "c:\PS-0265202330001.xml"

'-----------------------------------------------------------------------------------'
' Process Children For Parent Material (Node)                                
       '
'-----------------------------------------------------------------------------------'
Function ProcessChildren(objParent, ByRef objADORS, ByVal intCurrentLevel)

Dim intLevel

Do While True

	Set nodeTemp = objXMLDoc.createElement("Material")
	nodeTemp.nodeTypedValue = objADORS.Fields("DESCP").Value
	
	Set nodeAttribute = objXMLDoc.CreateAttribute("ID")
	nodeAttribute.Value = objADORS.Fields("MATERIAL").Value
	nodeTemp.SetAttributeNode(nodeAttribute)
	
	objParent.appendChild nodeTemp

	objADORS.moveNext

	If objADORS.EOF = True Then
	    Exit Function
	End If

	intLevel = CInt(objADORS.Fields("LEVEL").Value)

	If intLevel > intCurrentLevel Then
	   Call ProcessChildren(nodeTemp, objADORS, intLevel)
	Else
	   If intLevel < intCurrentLevel Then
	     Exit Function
	   End If
	End If
	
Loop

End Function


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent