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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.