Solved

Using xmldom setAttribute to update a specific node

Posted on 2001-08-09
1
646 Views
Last Modified: 2007-12-19
I'm new to XML and so setAttribute may not be the right method to use, but how do I add a new node-level attribut to a node. For example, given the following node (which is one of many nodes), how do I add an xyz attribute with an "abc" value.

<class name="Quote" abstract="no" version="1.0">
0
Comment
Question by:Martin Liss
1 Comment
 
LVL 4

Accepted Solution

by:
edmund_mitchell earned 50 total points
ID: 6369170
Hello MartinLiss

Here is an example from a website:
The original XML
<?xml version="1.0"?>
<note time="12:03:46">
     <to>Tove</to>
     <from>Jani</from>
     <heading>Reminder</heading>
     <body>Don't forget me this weekend!</body>
</note>

The XML after setting the attribute
<?xml version="1.0"?>
<note time="12:03:46" year="2000">
     <to>Tove</to>
     <from>Jani</from>
     <heading>Reminder</heading>
     
the code:

<html>
<body>
<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")

document.write("The original XML")
document.write("<xmp>" & xmldoc.xml & "</xmp>")

set x=xmlDoc.getElementsByTagName("note")
call x.item(0).setAttribute("year","2000")

document.write("The XML after setting the attribute")
document.write("<xmp>" & xmldoc.xml & "</xmp>")

</script>
</body>
</html>

It's an example from http://www.w3schools.com/dom/tryit.asp?filename=try_dom_setattribute

HTH

Edmund

0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mongodb hierarchy 2 59
Help with SimpleXML charts with PHP 4 101
Path of Workbook 3 86
MS SQL Database Generating XML using query 21 50
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question