473,323 Members | 1,547 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,323 software developers and data experts.

updating nodes?

i got this xml 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:

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:

<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>

Nov 12 '05 #1
1 1343


Patrick F wrote:

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;


You can cast the node to an element e.g.
XmlElement element = fetchnode as XmlElement;
then you can set
element.SetAttribute("id", i.ToString());

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

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

Similar topics

0
by: Brett O'Callaghan | last post by:
Hi Guys, any recommendations for the following - Have a "settings" XML file with things like <settings> <something>TRUE</something> <somethingelse>FALSE</somethingelse> </settings> In a...
3
by: Robin Tucker | last post by:
Hi, I'm in the process of implementing a multi-user system containing an adjacency list (tree structure). I'm using a TIMESTAMP field on each record in the adjacency list in order to tell when...
0
by: john wright | last post by:
I know windows controls are not multithreaded and need to run on the main thread. I have been trying to get a thread I have to update a tree view based on information I get. I have tried the...
2
by: WhiteWizard | last post by:
This should be easy, and it probably is, I just can't find anything on it. I have to build an XML Document object in memory, add some child nodes, save it, and then if another condition arises,...
1
by: Christian Rühl | last post by:
hey! what i wanna do sounds very simple at first, but it turned out to be a real bone crusher... i want to check if a treeView node is checked and if a correspondent node in my xml config file...
0
by: drop | last post by:
Hi, I'm currently working with the Treeview control in ASP .Net 2.0. The tree is filled dynamically based on data contained in a MySQL Database. Here is the exact behavior I want : 1 - User...
1
by: Tom | last post by:
Hey, I have a treeview control which i am reading and writing slots to (Its a player manager for Delta Force Black Hawk Down). At the moment, every 100ms it reads through the games memory to...
0
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the...
1
by: soni2926 | last post by:
hi, we currently have a site done using asp.net 2.0, one of the pages has a datagrid, which displays some information. currently there is a refresh button, but we want to change this so that every...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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.