Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 7th, 2006, 05:42 AM
Authorized User
 
Join Date: May 2006
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?

 
Old May 7th, 2006, 06:24 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
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)
 
Old May 7th, 2006, 08:13 AM
Authorized User
 
Join Date: May 2006
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old May 7th, 2006, 08:29 AM
Authorized User
 
Join Date: May 2006
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.






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





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