Solved

How to renumber ID field of xml file?

Posted on 2011-03-07
5
298 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:vcharles
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35062979
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
 

Author Comment

by:vcharles
ID: 35066052
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
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 35068497
Yikes!  That code was in error, huh? Let's try modifying line 9 to be:

    nodes = xdoc.SelectNodes("//Link_ID")
0
 

Author Closing Comment

by:vcharles
ID: 35070427
Thank You!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35070917
NP. Glad to help  : )
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now