I am appending a child node and I am using a variable called "xmlDoc" as the main DomDocument. As I drill down to the node I need to append xmlDoc is only pointing at each particular node on the document.
So after I have appended my file xmlDoc is pointing to that node and when I go to save the file (xmlDoc.Save) I lose everything except the node that I just appended.
Here is the code below, it is in
VB. I am stepping through the child nodes to get to the node "observation". I append the node and then I can only save that node. Ofcourse what I need to do is to save the entire file and not just the latest node I have drilled down to.
Code:
Public Sub UpdateXML(RadId, ObId, AzType, DisType, StartPnt, EndPnt, _
Bearing, RndBearing, Distance, Layer, Symbol, isObserved)
On Error GoTo ErrHandler:
Dim xmlDoc As DOMDocument
Dim nodeSection As IXMLDOMNode
Dim ObjElement As IXMLDOMElement
Dim NodeName As String
Dim x As Integer
Dim y As Integer
Set xmlDoc = New DOMDocument
xmlDoc.async = False
xmlDoc.Load (PathName)
Set objDom = xmlDoc
Set ObjElement = xmlDoc.documentElement
For x = 0 To ObjElement.childNodes.Length - 1
If "RadialDetails" = ObjElement.childNodes.item(x).NodeName Then Exit For
Next x
xmlDoc.loadXML _
(ObjElement.childNodes.item(x).xml)
Set ObjElement = xmlDoc.documentElement
For x = 0 To ObjElement.childNodes.Length - 1
If RadId = ObjElement.childNodes.item(x).Attributes(0).text Then Exit For
Next x
xmlDoc.loadXML _
(ObjElement.childNodes.item(x).xml)
Set ObjElement = xmlDoc.documentElement
Set nodeSection = ObjElement.selectSingleNode("Observations")
'if found append Point information
If Not nodeSection Is Nothing Then
nodeSection.appendChild CreateXML(xmlDoc, ObId, AzType, DisType, StartPnt, EndPnt, _
Bearing, RndBearing, Distance, Layer, Symbol, isObserved)
'line return
nodeSection.appendChild nodeSection.ownerDocument.createTextNode(vbCrLf)
xmlDoc.Save (PathName)
Else
MsgBox "Incomplete or missing file! Could not save details to file:" & vbCrLf & _
PathName, vbCritical, "Error"
End If
exithere:
Set xmlDoc = Nothing
Set ObjElement = Nothing
Set nodeSection = Nothing
Exit Sub
ErrHandler:
MsgBox "Error in clsXMLWorker.UpdateRadialXML" & vbCrLf & _
Err.Description & " " & Err.Number
Dim Form As Form
For Each Form In Forms
Unload Form
Next
End
End Sub
Can some one tell me how to back back out to the parent node before I save so I can save the entire file?
If you don't succeed you run the risk of failure. *Dan Quale