Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XML
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 7th, 2006, 05:42 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default changing xml document object with javascript

Here is a question about manipulating a document object with javascript:

To access the value of an attribute in an XML document via javascript in a separate html document, I can retrieve the attribute using the W3C XML DOM -

The XML looks like this:


<?xml version="1.0" encoding="UTF-8"?>
<notes xmlns:xlink="http://www.w3.org/1999/xlink">

    <stuff classed="working">

    </stuff>
</notes>


The javascript looks like this:


function getAtt()

{

var el;
var strOutput = "";

el = dataXML.documentElement.getElementsByTagName("stuf f");
//dataXML is a reference to the XML document object

strOutput = el[0].attributes.getNamedItem("classed").value;

document.getElementById("here").innerHTML = strOutput;
//to display the attribute value in the html document

}


What I would like to know is if it is possible to change the value of that attribute in the XML document object using javascript in my html page? Can I use the replaceChild(newChild, oldChild) method of the Node object, or something similar? So far I have not managed to achieve this.

Is the attribute "classed" a child of the "stuff" element?

Reply With Quote
  #2 (permalink)  
Old May 7th, 2006, 06:24 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If oElement is a reference to the stuff element:
Code:
var sCurrentValue = oElement.getAtttribute("classed");
oElement.setAttribute("classed", "broken");
--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old May 7th, 2006, 08:13 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow - Okay, let me try that out. Thanks!

Reply With Quote
  #4 (permalink)  
Old May 7th, 2006, 08:29 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

And it WORKS!

Thanks so much - its great to find a forum where questions get answered by people who know what they are talking about.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform xml to xml changing one tag. surfer97301 XSLT 2 April 21st, 2010 05:14 PM
Changing the Source Document mphare XSLT 2 March 14th, 2008 02:46 PM
changing style using javascript mattastic Javascript 3 September 21st, 2004 09:57 AM
document null or not an object Adam H-W Javascript 2 April 22nd, 2004 05:59 AM
document null or not an object Adam H-W Javascript How-To 2 February 18th, 2004 01:25 PM



All times are GMT -4. The time now is 07:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.