Solved

Help with changing table name in xml file

Posted on 2013-10-25
6
215 Views
Last Modified: 2013-10-26
Hello,

I have an xml file with <Row> as the table name, How do I change it to <Country> using VB.NET?

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
  • 3
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39600436
Hi Victor;

A little bit more information is needed to answer this question.

Can you post the structure of the XML document?
Is the XML document in a String variable in your code or in a file on your system?
0
 

Author Comment

by:vcharles
ID: 39600453
Hi,

Thye xml file is in the following format:

<Root>
<Row>
<Table_ID>1</Table_ID>
<Item1></Item1>
<Item2></Item2>
</Row>
<Row>
<Table_ID>2</Table_ID>
<Item1></Item1>
<Item2></Item2>
</Row>
<Row>
<Table_ID>3</Table_ID>
<Item1></Item1>
<Item2></Item2>
</Row>
</Root>
0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 39600678
Hi vcharles;

Here is a way to do what you want.

Imports System.Xml.Linq 

' XML as a string in code
Dim xmlStr = "<Root><Row><Table_ID>1</Table_ID><Item1></Item1><Item2></Item2></Row><Row><Table_ID>2</Table_ID><Item1></Item1><Item2></Item2></Row><Row><Table_ID>3</Table_ID><Item1></Item1><Item2></Item2></Row></Root>"
' Convert string to XML document
Dim xdoc = XElement.Parse(xmlStr)
' Get list of nodes to be replaced 
Dim rows = xdoc.Descendants("Row").ToList()
' Create the new Country node with the children of the old Row node
' and replace in original XML document
For i As Integer = 0 To rows.Count() - 1
    Dim newElement = New XElement("Country", rows(i).Elements())
    rows(i).ReplaceWith(newElement)
Next

' Convert the modified XML back to a string
Dim newXMLStr = xdoc.ToString()

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:vcharles
ID: 39600684
Thank You, will try it and get back to you.
0
 

Author Closing Comment

by:vcharles
ID: 39602824
Thank You.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 39602959
Not a problem Victor, glad to help.
0

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

688 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