Solved

How to renumber ID field of xml file?

Posted on 2011-03-07
5
297 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 74

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 74

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 74

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

20 Experts available now in Live!

Get 1:1 Help Now