Solved

Using xmldom setAttribute to update a specific node

Posted on 2001-08-09
1
644 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Building a string from an xml 6 99
JPA XML tag definition 2 67
XSLT: how to increment number value if attribute present 4 41
parse convert xml feed to text (python) 2 81
The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

806 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