473,795 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GetElemen tsByTagName("li st").Count); i++) {

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

I have used the rtnX.DocumentEl ement.SetAttrib ute 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 .DocumentElemen t.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 6539
da********@hotm ail.com (D Ratcliffe) wrote in
news:8e******** *************** ***@posting.goo gle.com:
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.GetElemen tsByTagName("li st").Count); i++) {

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

I have used the rtnX.DocumentEl ement.SetAttrib ute 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 .DocumentElemen t.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.CreateAttr ibute();
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
2141
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> </MasterElement>
3
18826
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 would like to use JavaScript as then I use Firefox as well as IE (tried some VBScript, fine in IE of course but no go in Firefox). I have copied an example from "XML Unleashed", but when I try it, I get the following error; A Runtime Error...
0
305
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 the data in the particular node I wanted to display). The javascript looked something like: function GetData() {
2
1989
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 fields are done populating. Can anyone think of a way for me to check when the following function finishes? function importXML(xmlQuery,xmlSrc,xmlTarget) {
3
4280
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 client. var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load("url of the persisted file");
8
3646
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
959
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 client. var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load(url);
2
5057
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 firstName="betty" lastName="Smith">I am at home</name> But I only see text "I am at home" did I do something wrong? Set xmlDom=CreateObject("Microsoft.XMLDOM") XMLDom.async =False
1
4226
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
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.