473,407 Members | 2,629 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,407 software developers and data experts.

XMLDOM - Add attribute to tag

Hello

In a nutshell, I am looping through an XML document in a for loop, and
I want to insert a given value as an element to each tag as I go
along. i.e.:

for (int i=0; i < (rtnX.GetElementsByTagName("list").Count); i++) {

// I want here to add the attribute "display" to the selected tag
}

I have used the rtnX.DocumentElement.SetAttribute method, but this
seems to append my new attribute to my <root> tag, rather than each
<item> tag as it loops through. Here's an example of the XML if it
helps

WHAT I HAVE GOT:

<root>
<item id="1">Rita</item>
<item id="2">Bob</item>
<item id="3">Sue</item>
</root>

WHAT I WANT TO END UP WITH:

<root>
<item id="1" ADDEDVAL="XXX">Rita</item>
<item id="2" ADDEDVAL="XXX">Bob</item>
<item id="3" ADDEDVAL="XXX">Sue</item>
</root>

And as I say, prevously I used the .DocumentElement.SetAttribute
method but this just kept inserting the value into the <root>.

Any help would be much appreciated.

Regards

Darren
Nov 13 '05 #1
1 6527
da********@hotmail.com (D Ratcliffe) wrote in
news:8e**************************@posting.google.c om:
Hello

In a nutshell, I am looping through an XML document in a for loop, and
I want to insert a given value as an element to each tag as I go
along. i.e.:

for (int i=0; i < (rtnX.GetElementsByTagName("list").Count); i++) {

// I want here to add the attribute "display" to the selected tag
}

I have used the rtnX.DocumentElement.SetAttribute method, but this
seems to append my new attribute to my <root> tag, rather than each
<item> tag as it loops through. Here's an example of the XML if it
helps

WHAT I HAVE GOT:

<root>
<item id="1">Rita</item>
<item id="2">Bob</item>
<item id="3">Sue</item>
</root>

WHAT I WANT TO END UP WITH:

<root>
<item id="1" ADDEDVAL="XXX">Rita</item>
<item id="2" ADDEDVAL="XXX">Bob</item>
<item id="3" ADDEDVAL="XXX">Sue</item>
</root>

And as I say, prevously I used the .DocumentElement.SetAttribute
method but this just kept inserting the value into the <root>.

Any help would be much appreciated.


1) get a reference to the current node. It is wise to first select
the nodes in a nodelist and foreach through that nodelist.
2) create a new attribute by using rtnX.CreateAttribute();
3) add it to the Attributes collection of the current node using
the Append method of that collection.

FB

--
Solutions Design : http://www.sd.nl
My open source .NET Software : http://www.sd.nl/software
My .NET Blog : http://weblogs.asp.net/FBouma
-------------------------------------------------------------------------
Nov 13 '05 #2

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

Similar topics

1
by: Mike Labman | last post by:
I'm parsing an XML document using the XMLDOM object in ASP. I am running into a problem with a section formatted like this: <MasterElement> TitleOfElement <Abbreviation> TOE </Abbreviation>...
3
by: reclusive monkey | last post by:
I am just starting out with XML. I've been playing with XML and XSLT, very nice indeed. I particularly like the filtering/ordering functions. Anyway, I have started to have a look at scripting, and...
0
by: BCM | last post by:
In ASP 3, I once did a page using javascript and XMLDOM that loaded up xml files, displayed their data, and automatically refreshed that data at 10 second intervals (not a whole page refresh: just...
2
by: jfizer | last post by:
I have a web app that uses a form with its fields populated from XML using Microsoft.XMLDOM. The problem is that Microsoft.XMLDOM functions seem to run on their own thread, so I dont know when the...
3
by: Robert Zurer | last post by:
Hello all, I want to load an in-memory XmlDocument from the server to the client and create an XMLDOM object using javascript. I can do it from a url by calling this Javascript from the...
8
by: Mr. x | last post by:
Hello, How can I use xmlpath technogy by xmldom. (or there is another technique, but not xmldom). I need some code samples, please. Thanks :)
0
by: Robert Zurer | last post by:
Hello all, I want to load an in-memory XmlDocument from the server to the client and create an XMLDOM object using javascript. I can do it from a url by calling this Javascript from the...
2
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I have the following code which I try to load an xml file, but in browser, I only get text value for each node, not whole xml string. I expect to see something like <name...
1
AnuSumesh
by: AnuSumesh | last post by:
Hi, I want to read the text property of XML file. My xml file is as follows: <?xml version="1.0"?> <Domain_Credentials> <User> anu </User>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.