Solved

Help with changing table name in xml file

Posted on 2013-10-25
6
207 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
  • 3
  • 3
6 Comments
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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
Comment Utility
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 62

Accepted Solution

by:
Fernando Soto earned 500 total points
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

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

Author Closing Comment

by:vcharles
Comment Utility
Thank You.
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
Not a problem Victor, glad to help.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

7 Experts available now in Live!

Get 1:1 Help Now