remove xml node in xml document

  • Thread starter Thread starter Que
  • Start date Start date
Q

Que

hi
i have the following xml document
<root>
<item>
<key>
<scode></scode>
</key>
<scode></scode>
<desc></desc>
<pc></pc>
</item>
<item>
<key>
<scode></scode>
</key>
<scode></scode>
<desc></desc>
<pc></pc>
</item>
<item>
<key>
<scode></scode>
</key>
<scode></scode>
<desc></desc>
<pc></pc>
</item>
</root>

how do i remove , the second scode node so that the document looks as
follows

<root>
<item>
<key>
<scode></scode>
</key>
<desc></desc>
<pc></pc>
</item>
<item>
<key>
<scode></scode>
</key>
<desc></desc>
<pc></pc>
</item>
<item>
<key>
<scode></scode>
</key>
<desc></desc>
<pc></pc>
</item>
</root>

thanks
Que
 
Have you used the xmldocument? Put your xml in a file and test with the following code:


Dim xmldoc As New Xml.XmlDocument()
Dim nodRoot As Xml.XmlNode

xmldoc.Load("c:\test.xml")
nodRoot = xmldoc.ChildNodes(0)

'write debug info
Debug.WriteLine("ChildNodes count: " & nodRoot.ChildNodes.Count)
'remove the 2nd node
nodRoot.RemoveChild(nodRoot.ChildNodes(1))
'write debug info
Debug.WriteLine("ChildNodes count: " & nodRoot.ChildNodes.Count)


Also, you can use XPath to find a desired node to further remove.

[]s
Cesar
 
Back
Top