CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Amend XML

  1. #1
    Join Date
    Jan 2011
    Posts
    20

    [ANSWERED] Amend XML

    Hi,

    I have the following XML document:

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <MAP>
      <TILES>
        <TILE ID="1">
          <START>FALSE</START>
          <EXIT>FALSE</EXIT>
        </TILE>
        <TILE ID="2">
          <START>FALSE</START>
          <EXIT>FALSE</EXIT>
        </TILE>
        <TILE ID="3">
          <START>FALSE</START>
          <EXIT>FALSE</EXIT>
        </TILE>
      </TILES>
    </MAP>
    If I want to say search for a tile node with id attribute of 3 and change the START node to TRUE.

    I have got this so far:
    Code:
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("xmlfile.xml");
                XmlNode node = xmlDoc.SelectSingleNode("/MAP/TILES/TILE/START");
                node.Attributes[0].Value = "TRUE";
                xmlDoc.Save("xmlfile.xml");
    But I have no idea how to find and change only the node with ID = 3.

    Thanks

    Jay
    Last edited by JayWeb; March 18th, 2011 at 08:32 PM.

  2. #2
    Join Date
    Jan 2011
    Posts
    20

    Re: Amend XML

    Found the answer.

    XmlNodeList nodeList = xmlDoc.SelectNodes("/MAP/TILES/TILE[@ID='3']");

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