I’ve been trying to add/update and delete nodes from an xml string.
However (as this project demonstrates) after adding a second node to an xml document the document becomes corrupt.
I’ve attached a simple project that demonstrates the issue.
There is one button that steps through tests…
The first press adds a node to the document. (Successfully)
The second press adds a second node to the document (and the document gets corrupted.)
The third press deletes (or it would if the document wasn’t corrupted.) a nod.
This method I suspect is the culprit…
[code]Private Sub UpdateCfg(pipe as string, Tag as String, mode as updateOperation)
dim ExistingNode, NewNode as XmlNode
dim cfgxml, pipelinexml as XmlDocument
if mCfg <> “” then cfgxml = new XmlDocument(mCfg)
if pipe <> “” then pipelinexml = new XmlDocument(pipe)
if cfgxml <> nil and Tag <> “” then
ExistingNode = DoesPipeLineExist(Tag, cfgxml)
end if
if pipelinexml <> nil then
NewNode = cfgxml.ImportNode(pipelinexml.FirstChild, true)
end if
select case mode
case updateOperation.delete
if ExistingNode <> Nil then
cfgxml.FirstChild.RemoveChild(ExistingNode)
end if
case updateOperation.update
if NewNode <> nil and ExistingNode <> Nil then
cfgxml.FirstChild.ReplaceChild(NewNode, ExistingNode)
end if
case updateOperation.add
if NewNode <> Nil then
cfgxml.FirstChild.AppendChild(NewNode)
end if
end select
mCfg = “”
DumpXml(cfgxml.FirstChild, 0, mCfg)
End Sub[/code]