RE: [xmljs-users] Cannot write back to root document object...
Brought to you by:
djoham,
witchhunter
From: David J. <dj...@ya...> - 2004-07-30 17:42:22
|
Hi Eljon! I think the problem is that you're setting the node Value on the element, rather than the text node child of the element. You have pageRoot.getElementsByTagName(tElement).item(tOrder-1).getElementsByTagName('active').item(0).setNodeValue("No"); which will set the node value of the <active> element, but not the text node under it. I think what you want to do is this: pageRoot.getElementsByTagName(tElement).item(tOrder-1).getElementsByTagName('active').item(0).getFirstChild().setNodeValue("No"); Note the addition of the getFirstChild() call. That will return the text node that you're actually interested in. Actually, on text nodes you're supposed to use setData rather than setNodeValue, but if you look at the code, all xmljs does in a setData is call setNodeValue so it doesn't really matter from a technical perspective... The code above will set the node data/value (the visible text so to speak) of the text node enclosed by the <active> node. When reading this value, you'll want to also make sure you're reading from the text node to make sure you're actually getting the node value of the text object. You can sometimes get away with not doing this, but it's not advised. Please go ahead and give that a shot and let us know how it turns out.... David --- Eljon Greene <eg...@re...> wrote: > Sure, > > Here is an example of the code: > > function removeNode(tElement,tOrder){ > if(pageRoot.getElementsByTagName(tElement).item(tOrder-1) != > null) { > tNode = > pageRoot.getElementsByTagName(tElement).item(tOrder-1); // Get first > element by node name (i.e. section, fieldgroup, fields) > > tNode.getElementsByTagName('active').item(0).setNodeValue("No"); // Set > active element to "No" > try { > > alert(tNode.getElementsByTagName('active').item(0).getNodeValue()); // > Displays "No" > > alert(tNode.getElementsByTagName('active').item(0).getXML()); // > Displays <active>Yes</active> > > } catch(e) { // Catch any exception > if(e.code == > DOMException.NO_MODIFICATION_ALLOWED_ERR) { > // display the error message > alert("XML Exception Error: Code > not remove " + tElement + "."); > } else { > alert("Unknown exception"); > alert(e.code); > } > } > } else { > alert("Null object"); > } > } > > Thanks for your assistance. > > Eljon > > -----Original Message----- > From: xml...@li... > [mailto:xml...@li...] On Behalf Of David > Joham > Sent: Thursday, July 29, 2004 11:33 AM > To: Eljon Greene; xml...@li... > Subject: Re: [xmljs-users] Cannot write back to root document object... > > > > Hi Eljon! > > Can you whip up a quick recreation of the problem you're seeing please? > I'll take a look and see what's up... > > > David > > --- Eljon Greene <eg...@re...> wrote: > > > Hey guys, > > > > I am new to XML for <script>. Everything is coming along pretty good > > except for one thing...That is trying to write back to the parent > > document node so that I can save this information on the server. I > > can use "DOMNode.setNodeValue()" and then use "DOMNode.getNodeValue()" > > > and it works. However when I try "DOMNode.getXML()" the old value > > still exists...I am trying to use global variables in my method > > instead of the local variables. What am I doing wrong and how do I > > write back to the "DOMDocument"? Thanks... > > > > > > Eljon Greene > > Web Software Engineer > > 877.394.5644 \\ main > > 904.567.2127 \\ direct > > eg...@re... > > www.recruitmax.com > > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by OSTG. Have you noticed the changes on > Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, > one more big change to announce. We are now OSTG- Open Source Technology > Group. Come see the changes on the new OSTG site. www.ostg.com > _______________________________________________ > xmljs-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmljs-users > |