Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
| Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2004, 08:22 PM
Registered User
 
Join Date: Nov 2004
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating nodes?

i got this xml code:


Code:
    <formmonthnames>

        <monthnames id="">January</monthnames>

        <monthnames id="">February</monthnames>

        <monthnames id="--">March</monthnames>

        <monthnames id="">April</monthnames>

        <monthnames id="">May</monthnames>

        <monthnames id="">June</monthnames>

        <monthnames id="">July</monthnames>

        <monthnames id="">August</monthnames>

        <monthnames id="--">September</monthnames>

        <monthnames id="">October</monthnames>

        <monthnames id="">November</monthnames>

        <monthnames id="">December</monthnames>

    </formmonthnames>


now im trying to figure out how to update the id attribute of those monthnames.
i got this code to retrive the nodes:

Code:
            string strAttr = "";

            XmlNodeList nodelist;

            XmlDocument mydoc = new XmlDocument();



            int i = 10;



            try

            {

                mydoc.Load(strFilename);

                nodelist = mydoc.SelectNodes("//formmonthnames//monthnames");



                if (nodelist.Count > 0) 

                {

                    foreach (XmlNode fetchnode in nodelist) 

                    {

                        if (fetchnode.Attributes.Count > 0) 

                        {                            

                            strAttr = fetchnode.Attributes[0].Value;

                            if (strAttr != "--") 

                            {

                                // update the node with the value inside i

                                i = i + 5;

                            }

                        }                                            

                    }

                }

            }

            catch (Exception e) 

            {

                Response.Write = "Error: " + e.Message;

            }

how do i update the node with the value of i and how do i return the updated node to the xml file?

the result should look like this:


Code:
    <formmonthnames>

        <monthnames id="10">January</monthnames>

        <monthnames id="15">February</monthnames>

        <monthnames id="--">March</monthnames>

        <monthnames id="20">April</monthnames>

        <monthnames id="25">May</monthnames>

        <monthnames id="30">June</monthnames>

        <monthnames id="35">July</monthnames>

        <monthnames id="40">August</monthnames>

        <monthnames id="--">September</monthnames>

        <monthnames id="45">October</monthnames>

        <monthnames id="50">November</monthnames>

        <monthnames id="55">December</monthnames>

    </formmonthnames>




Similar Threads
Thread Thread Starter Forum Replies Last Post
How to value in b/n nodes Swetha XSLT 1 May 20th, 2008 12:20 PM
Nodes ....'For Each' problem. Neal XSLT 3 February 13th, 2006 08:57 AM
differentiating between two nodes RazoRmedia XSLT 4 February 9th, 2006 06:25 AM
ASP3 / XMLDOM / updating nodes -- HELP PLEASE Michael Yevdokimov XML 1 January 3rd, 2005 12:37 PM
ASP3 / XMLDOM / updating nodes -- HELP PLEASE Michael Yevdokimov Classic ASP XML 0 December 30th, 2004 11:59 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.