Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to renumber ID field of xml file?

Posted on 2011-03-07
5
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

609 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