Solved

Using xmldom setAttribute to update a specific node

Posted on 2001-08-09
1
647 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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