How to renumber ID field of xml file?

Hello,

I have an xml file in the folowing order
<Row>
<LInk_ID>1</LInk_ID>
</Row>
<Row>
<LInk_ID>0</LInk_ID>
</Row>
<Row>
<LInk_ID>3</LInk_ID>
</Row>
<Row>
<LInk_ID>2</LInk_ID>
</Row>
<Row>
<LInk_ID>6</LInk_ID>
</Row>
<Row>
<LInk_ID>6</LInk_ID>
</Row>
<Row>
<LInk_ID>8</LInk_ID>
</Row>
<Row>
<LInk_ID>11</LInk_ID>
</Row>

How do I loop through the xml file to sort Link_ID is sequential order starting with zero?

Thanks,

Victor
vcharlesAsked:
Who is Participating?
 
käµfm³d 👽Connect With a Mentor Commented:
Yikes!  That code was in error, huh? Let's try modifying line 9 to be:

    nodes = xdoc.SelectNodes("//Link_ID")
0
 
käµfm³d 👽Commented:
Try this:
Imports System.Xml

...

Dim xdoc As New XmlDocument
Dim nodes As XmlNodeList

xdoc.Load("filename.xml")
nodes = xdoc.SelectNodes("//Row")

For i As Integer = 0 To nodes.Count - 1
    nodes(i).InnerText = i.ToString()
Next

xdoc.Save("output.xml")

Open in new window

0
 
vcharlesAuthor Commented:
Hi,


Where do I specify Link_ID? The Row tags contain other data elements I did not include in my previous post.

Thanks,

Victor
0
 
vcharlesAuthor Commented:
Thank You!
0
 
käµfm³d 👽Commented:
NP. Glad to help  : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.