Link to home
Start Free TrialLog in
Avatar of Victor  Charles
Victor CharlesFlag for United States of America

asked on

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
Avatar of kaufmed
kaufmed
Flag of United States of America image

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

Avatar of Victor  Charles

ASKER

Hi,


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

Thanks,

Victor
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank You!
NP. Glad to help  : )