CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    8

    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.

  2. #2
    Join Date
    Aug 2005
    Posts
    132

    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?

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Replace main node name

    Quote 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).
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured