Solved

Using xmldom setAttribute to update a specific node

Posted on 2001-08-09
1
642 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
jaxb jaxp sax dom 7 43
Split Records in XML using XSLT 2.0 3 39
XSLT Assistance 9 44
Specific format 21 140
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 …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now