Help with renaming multiple data elements using VB.NRT

Hi,
Hoe do you tename multiple data elements using VB.NET?

Victor
vcharlesAsked:
Who is Participating?
 
Fernando SotoRetiredCommented:
Hi Victor;

Code like this will do what you need.
'' Create a Dictionary object that has a key of the node name and assign the value
'' of what you want to change that node name too. So in this example change all
'' node names NSC to XXX, NSN to YYY and NAS to ZZZ
Dim lookup As Dictionary(Of String, String) = New Dictionary(Of String, String)() From _
                                              { _
                                                {"NSC", "XXX"}, _
                                                {"NSN", "YYY"}, _
                                                {"NAS", "ZZZ"}
                                              }
''Load the XML document into memory
Dim xdoc = XDocument.Load("C:\Working Directory\RenameNodes.xml")
'' Get all the nodes into a list of XElements
Dim results = (From node In xdoc.Descendants()
               Select node)

'' Iterate through all the nodes in the list
For Each node As XElement In results
    '' Get the currect name of the node
    Dim name As String = node.Name.ToString()
    '' Check to see if it is one of the nodes to have its name changed
    If lookup.ContainsKey(name) Then
        '' It is, get the new name for the node
        Dim newName As String = lookup(name)
        '' Change the node name
        node.Name = newName
    End If
Next

xdoc.Save("C:\Working Directory\NodesRenamed.xml")

Open in new window

0
 
Mike EghtebasDatabase and Application DeveloperCommented:
In the code window, after ctrl+F, you get:findreplace1: Click on ^ to hide replace box. Click again to show it.
2: Click here to replace the current highlighted item.
3. Click here to replace all in the scope selected in item 4.
4. Select scope of Find/replace.

re: data elements?
If this pertains to meta data in the database, then it has to be done in SQL Server using TSQL ALTER command.
0
 
vcharlesAuthor Commented:
Hi,

I need to change the data during run time.

Thanks,

Victor
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
Fernando SotoRetiredCommented:
Hi Victor;

to your statement, "How do you rename multiple data elements using VB.NET?", Victor this is a very vague question and without further information is impossible to answer. Where is the data being stored in the application, is it in a data table object, an XML object, an SQL data table object, an array or something else. In that statement you say, "rename multiple data elements", you are not asking to change the variable name of the object at runtime, are you?
0
 
vcharlesAuthor Commented:
Hi Fernando,

What I meant was if file1 contains:

<Root>
<Table>
<ID></ID>
<NSC></NSC>
<NSN></NSN>
<NAS></NAS>
</Table>
</Root>

How do I change the field names as shown in File 2 using VB.NET?

<Root>
<Table>
<ID></ID>
<XXX></XXX>
<YYY></YYY
<ZZZ></ZZZ>
</Table>
</Root>


Thanks,

Victor
0
 
vcharlesAuthor Commented:
Thank You.
0
 
Fernando SotoRetiredCommented:
Hi Victor;

Please close the question by assigning points to the solution that answered your question.
0
 
vcharlesAuthor Commented:
Thank You.
0
 
Fernando SotoRetiredCommented:
Not a problem Victor, always glad to help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.