473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

How to change name of an XML node

KK
Hi,

Is there any way to change the name of XML node? In the following xml,
I want to change the node <FIELD_1> to <FIELD_ITEM> in all the places.
Ex:
<NewDataSet>
<LOOKUP>
<FIELD_1>First_Item113</FIELD_1>
<FIELD_2>First_Item224</FIELD_2>
</LOOKUP>
<LOOKUP>
<FIELD_1>Second_Item11</FIELD_1>
<FIELD_2>Second_Item222</FIELD_2>
</LOOKUP>
<LOOKUP>
<FIELD_1>Third_Item11</FIELD_1>
<FIELD_2>Third_Item22</FIELD_2>
</LOOKUP>
</NewDataSet>

I am using the following asp.net code, and I am able to read FIELD_1 in
localname but I am not able to change. any ideas?

Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
'Create the XML Document
m_xmld = New XmlDocument
'Load the Xml file
m_xmld.Load("c:\temp\test.xml")
'Get the list of name nodes
m_nodelist = m_xmld.SelectNodes("/NewDataSet/LOOKUP")
Dim i As Integer
For Each m_node In m_nodelist
'CHANGE LOCALNAME
Next
m_xmld.Save("c:\temp\test.xml")
Thanks

Dec 2 '05 #1
1 3370


KK wrote:

Is there any way to change the name of XML node? In the following xml,
I want to change the node <FIELD_1> to <FIELD_ITEM> in all the places. Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode


No, the DOM as implemented in .NET does not allow you to change the name
of an already created node, you would need to create a new node with the
desired name, then make sure you copy attributes as needed, then move
child nodes as needed, then replace the old node with the new node.

Or you could write an XSLT stylesheet doing such stuff.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Dec 2 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex Sab | last post by:
Hi, I am having trouble describing in a schema that elements can be mandatory in one part and not mandatory in another part of the xml document. Here is a sample xml file <Model:Templates>...
15
by: Henning Vestergaard Poulsen | last post by:
Hi, I have a problem that I hope someone can help me with. I'm building a web page with pictures I've taken with my digital camera. I have succeded making a javacript that, when clicking on a...
3
by: zerdust | last post by:
how can I change the name of XML node? this is sample <?xml version="1.0"?> <adresboek> <adres> <naam>Mark van Renswoude</naam> <straat>ddden 24</straat> <plaats>Scddd</plaats>...
2
by: Rick | last post by:
I have an XML document that is generated from Infopath, I need to change the value of a namespace that is defined in a node in the form: <xsf:xDocumentClass "xmlns:my=valuehere">. when i navigate...
0
by: KK | last post by:
Hi, Is there any way to change the name of XML node? In the following xml, I want to change the node <FIELD_1> to <FIELD_ITEM> in all the places. Ex: <NewDataSet> <LOOKUP>...
3
by: ina | last post by:
Hello all, I have this xml file: <FS> <Style> <Name>Luca</Name> <Strategy> <Strategy_Style>Geo\Asia</Strategy_Style> <Strategy_Style>Geo\America</Strategy_Style>
7
by: dotnetnoob | last post by:
i keep getting Object references not set to an instance of an object from this code: Private Sub EqBinding() Dim x As Integer x = 0 Do If CStr(arlsType.Item(x)) = "Bacnet Point" Then Dim...
1
by: =?Utf-8?B?VG9uZQ==?= | last post by:
Hi, I need to change a value of an element in an XML file, I have been trying to select the node to edit but can only get as far as component and have to itterate through.. XmlDocument doc =...
0
by: =?Utf-8?B?amFjb2I=?= | last post by:
hello guys i have a problems with xmls how to set or change values from xml node elements from an existent xml file using C# from this xml file <xml version="1.0"> <students>...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.