Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using xmldom setAttribute to update a specific node

Posted on 2001-08-09
1
Medium Priority
?
651 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 200 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

Interactive Way of Training for the AWS CSA Exam

An interactive way of learning that will help you visualize core concepts so that you can be more effective when taking your AWS certification exam.  Built for students by a student to help them understand the concepts that they are being taught.

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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