-
March 9th, 2006, 10:53 AM
#1
Replace main node name
This might be a simple question....
I have a simple xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Content>
<Element1>ele2</Element1>
<Element2>ele2</Element2>
</Content>
I want to replace Content with Page and I tried:
XmlNode firstNode = xmlDoc.SelectSingleNode("Content");
firstNode.LocalName.Replace("Content","Page");
Obviously I am doing it wrong or not understanding it properly, so, I am not getting the desired output. What is the correct api that I should use?
I am using C# for my code.
-
March 9th, 2006, 05:02 PM
#2
Re: Replace main node name
I'm not familiar with C#, but what is the output you're getting from this code? What XML tool are you using to parse and update the XML or does C# come with one as default?
-
March 12th, 2006, 04:35 AM
#3
Re: Replace main node name
Originally Posted by GuOddian
I'm not familiar with C#, but what is the output you're getting from this code? What XML tool are you using to parse and update the XML or does C# come with one as default?
The XML namespace from the .NET Framework.
This can't work
Code:
firstNode.LocalName.Replace("Content","Page");
because firstNode.LocalName is only a get property, so it won't affect the local name of the node.
I think you have to create a new mode and then replace the old one with the new one (ReplaceChild).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|