Home All Groups Group Topic Archive Search About

remove xml node in xml document

Author
12 May 2006 9:11 PM
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

Author
12 May 2006 10:17 PM
ronchese
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


Show quoteHide quote
"Que" <aq.maho***@gmail.com> wrote in message news:1147468267.715035.33390@i39g2000cwa.googlegroups.com...
> 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
>