Thread: Re: [xmljs-users] deep copy nodes between xml documents with JS
Brought to you by:
djoham,
witchhunter
From: Barry B. <Ba...@al...> - 2004-12-13 15:26:02
|
thanx for your help, James. holy mackrel! that's exactly what I'm trying to do. Create a master xml = doc (data island) and then add nodes (copy) to it from the = xmlhttprequest xml doc. the xmlhttprequest *has* to be there - it's providing lookup data that = gets displayed in a form for editing (think remote procedure calls). As each lookup happens I have to store the previous changes somewhere = (the master doc?) and then post that as one hidden field back to the = server for processing. The master doc basically provides a new root node = and some id attributes, ready to be filled with child nodes from the = xmlhttprequest doc. I've been beating my head against the wall trying to get this to work. = It never occured to me that they'd be two incompatable xml objects. looks like I've been tricked into thinking this could work because I can = use some JS functions to manip the xmlhttpreqest doc already (to display = in form elements or post back to the server, yes, but not copy or = clone). now I'm really stuck. any ideas on how I can aggrigate the results of = each lookup (ie: add nodes) to send back to the server in one hidden = form field? looks like the data island idea won't work.... (in panic mode) I'm thinking that, since there's form elements involved, = I might get away with creating xml nodes on the fly and just copying the = data and attribute values (up to 4 per child node). I've had to do = something similar serverside with ColdFusion - java didn't want to play = nice (eg like this: = http://www.spike.org.uk/blog/index.cfm?do=3Dblog.day&day=3D4&month=3D6&ye= ar=3D2004) any suggestions are most appreciated worried... barry.b -----Original Message----- From: xml...@li... on behalf of James S. = Elkins Sent: Wed 8/12/2004 12:50 AM To: xml...@li... Cc:=09 Subject: [xmljs-users] Re: xmljs-users digest, Vol 1 #50 - 2 msgs Barry, Do I understand you correctly as saying that you're creating the first = DOM=20 in <XML for Script> and the second DOM using the browser's native=20 XmlHttpRequest object? If so, you can't copy nodes from one to the other = because one is a JavaScript object and the other is an ActiveX or = Mozilla=20 object. The standard DOM methods may be the same, but the interfaces are = implemented differently. James At 10:19 PM 12/6/2004, you wrote: >Send xmljs-users mailing list submissions to > xml...@li... > >To subscribe or unsubscribe via the World Wide Web, visit > https://lists.sourceforge.net/lists/listinfo/xmljs-users >or, via email, send a message with subject or body 'help' to > xml...@li... > >You can reach the person managing the list at > xml...@li... > >When replying, please edit your Subject line so it is more specific >than "Re: Contents of xmljs-users digest..." > > >Today's Topics: > > 1. deep copy nodes between xml documents with JS (Barry Beattie) > 2. Re: deep copy nodes between xml documents with JS (David Joham) > >--__--__-- > >Message: 1 >Date: Mon, 6 Dec 2004 17:58:41 +1000 >From: "Barry Beattie" <Ba...@al...> >To: <xml...@li...> >Subject: [xmljs-users] deep copy nodes between xml documents with JS > >hi all > >I've got a simple xml doc loaded on a page. I then get an additional = xml >doc using the xmlhttprequest object. > >what I want to do is get a deep copy of a particular node from the >additional doc and append it to the first one. > >I've tried importNode(), various combinations of cloneNode(), et all, >but can't seem to snag it. > >can anyone see where I'm going wrong? > >thanx >barry.b > > >here's the JS, run after the xmlhttprequest object gets each additional >doc > > function addAddressToMasterDoc(xmlAddress){ > var addressNode =3D3D xmlAddress.firstChild; > masterXmlDoc.importNode(addressNode); > }=3D20 > > > >masterXmlDoc (before): >=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D= 3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D > ><entity id=3D3D"12345" type=3D3D"student"> > <fname>Fred</fname> > <lname>Flintstone</lname> ></entity> > > >xmlAddress: >=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D= 3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D ><address addrType=3D3D"residential"> > <addr1>12 stone st</addr1> > <addr2>Bedrock</addr2> ></address> > >masterXmlDoc (after - what I'm trying to get): >=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D= 3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D3D=3D >=3D3D=3D3D=3D3D=3D3D=3D3D ><entity id=3D3D"12345" type=3D3D"student"> > <fname>Fred</fname> > <lname>Flintstone</lname> > <address addrType=3D3D"residential"> > <addr1>12 stone st</addr1> > <addr2>Bedrock</addr2> > </address> ></entity> > > > > >--__--__-- > >Message: 2 >Date: Mon, 6 Dec 2004 08:18:56 -0800 (PST) >From: David Joham <dj...@ya...> >Subject: Re: [xmljs-users] deep copy nodes between xml documents with = JS >To: Barry Beattie <Ba...@al...>, = xml...@li... > > >What XML do you get after your clone/import? I won't be able to look at = >this until tonight, but >what you're describing should work -at least on first inspection... > >David > >--- Barry Beattie <Ba...@al...> wrote: > > > hi all > > > > I've got a simple xml doc loaded on a page. I then get an additional = xml > > doc using the xmlhttprequest object. > > > > what I want to do is get a deep copy of a particular node from the > > additional doc and append it to the first one. > > > > I've tried importNode(), various combinations of cloneNode(), et = all, > > but can't seem to snag it. > > > > can anyone see where I'm going wrong? > > > > thanx > > barry.b > > > > > > here's the JS, run after the xmlhttprequest object gets each = additional > > doc > > > > function addAddressToMasterDoc(xmlAddress){ > > var addressNode =3D xmlAddress.firstChild; > > masterXmlDoc.importNode(addressNode); > > } > > > > > > > > masterXmlDoc (before): > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= > > <entity id=3D"12345" type=3D"student"> > > <fname>Fred</fname> > > <lname>Flintstone</lname> > > </entity> > > > > > > xmlAddress: > > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > > <address addrType=3D"residential"> > > <addr1>12 stone st</addr1> > > <addr2>Bedrock</addr2> > > </address> > > > > masterXmlDoc (after - what I'm trying to get): > > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D > > <entity id=3D"12345" type=3D"student"> > > <fname>Fred</fname> > > <lname>Flintstone</lname> > > <address addrType=3D"residential"> > > <addr1>12 stone st</addr1> > > <addr2>Bedrock</addr2> > > </address> > > </entity> > > > > > > > > > > ------------------------------------------------------- > > SF email is sponsored by - The IT Product Guide > > Read honest & candid reviews on hundreds of IT Products from real = users. > > Discover which products truly live up to the hype. Start reading = now. > > http://productguide.itmanagersjournal.com/ > > _______________________________________________ > > xmljs-users mailing list > > xml...@li... > > https://lists.sourceforge.net/lists/listinfo/xmljs-users > > > > > > >--__--__-- > >_______________________________________________ >xmljs-users mailing list >xml...@li... >https://lists.sourceforge.net/lists/listinfo/xmljs-users > > >End of xmljs-users Digest ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.=20 http://productguide.itmanagersjournal.com/ _______________________________________________ xmljs-users mailing list xml...@li... https://lists.sourceforge.net/lists/listinfo/xmljs-users |
From: Barry B. <Ba...@al...> - 2004-12-14 05:53:11
|
ah ha! now I'm cooking! thankyou James (and also David) xmlFragment =3D parser.loadXML(xmlToAdd.xml.toString()); where "xmlToAdd" is the ActiveX xml doc and the parser is the w3c vers (I gave up on the classic - sorry) all I gotta do is turn "xmlFragment" (not a real DocumentFragment yet) into something I can insert into the master=20 there isn't really a copyNode(deep) or insertFragment(node) is there... ...any suggestions? perhaps loop over each xmlFragment.ChildNodes and .attributes, adding them to the master (using createTextnode, createAttribute, etc)? thank heaps barry.b PS: [James and David:] the penny has (finally) dropped re: diff xml implementation, so much so that (later) I'll convert the ActiveX version to the W3C version as soon as the xnlhttprequest retrieves the data (at the moment I'm doing it before populating the form - my bad). I'll do the same with the firefox version when I get that working. -----Original Message----- From: xml...@li... [mailto:xml...@li...] On Behalf Of James S. Elkins Sent: Tuesday, 14 December 2004 2:25 AM To: David Joham; xml...@li...; Barry Beattie Subject: Re: [xmljs-users] deep copy nodes between xml documents with JS Barry, Try dumping the DOM obtained via XmlHttpRequest to an XML string and then=20 loading the XML into a new document in <XML for Script> to get it into the=20 proper implementation. ;) Thanks, James At 10:14 AM 12/13/2004, you wrote: > > the xmlhttprequest *has* to be there - it's providing lookup data that=20 > gets displayed in a form > > for editing (think remote procedure calls). > >There's no reason why you can't use xmlhttprequest and XML for <SCRIPT> at=20 >the same time, is >there? It should be possible to use xmlhttprequest and simply insert the=20 >resulting xml string from >the request object into an XML for SCRIPT DOM object. Standardizing on a=20 >single DOM Implementation >should get you past this and will likely prevent a whole host of other=20 >problems later. Since the >API of the two dom objects should be pretty much the same, it shouldn't >even require much (if any) >rework on your part. > >You could also look into the xmlIO functions of XML for <SCRIPT> to get >your XML String from the >server and do your RMI. However, if you're using browsers that you know >support xmlhttprequest, >I'll be the first to admit that object does provide a more robust API and=20 >less hoops to jump >through. > > > > > As each lookup happens I have to store the previous changes somewhere=20 > (the master doc?) and then > > post that as one hidden field back to the server for processing. The > master doc basically > > provides a new root node and some id attributes, ready to be filled=20 > with child nodes from the > > xmlhttprequest doc. > > > >Again, the master doc should just be an XML for SCRIPT DOM object > > > now I'm really stuck. any ideas on how I can aggrigate the results of=20 > each lookup (ie: add > > nodes) to send back to the server in one hidden form field? looks like=20 > the data island idea > > won't work.... > >xmlhttprequest should be fine here, as long as you use it just for data >retrieval. If you're >talking xml data islands (the IE proprietary thing) I think maybe you're=20 >making things harder for >yourself than you have to. > >Is there some reason you can't post some simple source code to help us=20 >help you out? A very simple >recreation that outlines what you're trying to do will go a long way in >helping us understand your >environment. > > > > > (in panic mode) > > > >Don't panic, find your towel and post some source code :) > >David ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.=20 http://productguide.itmanagersjournal.com/ _______________________________________________ xmljs-users mailing list xml...@li... https://lists.sourceforge.net/lists/listinfo/xmljs-users |
From: David J. <dj...@ya...> - 2004-12-14 16:12:48
|
> all I gotta do is turn "xmlFragment" (not a real DocumentFragment yet) > into something I can insert into the master > > there isn't really a copyNode(deep) or insertFragment(node) is there... Creating a DOMDocumentFragment and inserting it into the document using the standard append*/insert* methods should do the trick for you. http://xmljs.sourceforge.net/website/documentation-w3cdom-DOMDocument.html#DOMDocumentCreateDocumentFragment David |
From: Barry B. <Ba...@al...> - 2004-12-16 04:14:35
|
ach, I've narrowed it down. It's the adding of the other doc's element to the fragment that it doesn't like // xmlToAdd and masterXmlDoc are both xml docs addrToAdd =3D xmlToAdd.documentElement; doc_frag =3D masterXmlDoc.createDocumentFragment(); doc_frag.appendChild(addrToAdd); ////// here \\\\\ masterAddressRoot =3D masterXmlDoc.getElementsByTagName("addresses").item(0); masterAddressRoot.appendChild(doc_frag); alert(masterXmlDoc);=20 I've seen lots of examples where the "guts" of the fragment is created (createElement) but no where is it an existing node of another doc. is this the correct reference to the other xml node? thanx barry.b BTW, this works just fine addrToAdd =3D xmlToAdd.documentElement; // get the parent the "address" node masterAddressRoot =3D masterXmlDoc.getElementsByTagName("addresses").item(0); doc_frag =3D masterAddressRoot.importNode(addrToAdd, true); masterAddressRoot.appendChild(doc_frag); alert(masterXmlDoc); -----Original Message----- From: David Joham [mailto:dj...@ya...]=20 Sent: Wednesday, 15 December 2004 2:13 AM To: Barry Beattie; xml...@li... Subject: RE: [xmljs-users] deep copy nodes between xml documents with JS > all I gotta do is turn "xmlFragment" (not a real DocumentFragment yet) > into something I can insert into the master=20 >=20 > there isn't really a copyNode(deep) or insertFragment(node) is there... Creating a DOMDocumentFragment and inserting it into the document using the standard append*/insert* methods should do the trick for you. http://xmljs.sourceforge.net/website/documentation-w3cdom-DOMDocument.ht ml#DOMDocumentCreateDocumentFragment David |
From: David J. <dj...@ya...> - 2004-12-16 04:44:11
|
Does this help? http://xmljs.sourceforge.net/website/documentation-w3cdom-DOMDocument.html#DOMDocumentImportNode I'm still baffled by what you're trying to do... David --- Barry Beattie <Ba...@al...> wrote: > > ach, I've narrowed it down. It's the adding of the other doc's element > to the fragment that it doesn't like > > // xmlToAdd and masterXmlDoc are both xml docs > > addrToAdd = xmlToAdd.documentElement; > doc_frag = masterXmlDoc.createDocumentFragment(); > doc_frag.appendChild(addrToAdd); ////// here \\\\\ > masterAddressRoot = > masterXmlDoc.getElementsByTagName("addresses").item(0); > masterAddressRoot.appendChild(doc_frag); > alert(masterXmlDoc); > > I've seen lots of examples where the "guts" of the fragment is created > (createElement) but no where is it an existing node of another doc. > > is this the correct reference to the other xml node? > > thanx > barry.b > > BTW, this works just fine > > addrToAdd = xmlToAdd.documentElement; > // get the parent the "address" node > masterAddressRoot = > masterXmlDoc.getElementsByTagName("addresses").item(0); > doc_frag = masterAddressRoot.importNode(addrToAdd, true); > masterAddressRoot.appendChild(doc_frag); > alert(masterXmlDoc); > > > > -----Original Message----- > From: David Joham [mailto:dj...@ya...] > Sent: Wednesday, 15 December 2004 2:13 AM > To: Barry Beattie; xml...@li... > Subject: RE: [xmljs-users] deep copy nodes between xml documents with JS > > > all I gotta do is turn "xmlFragment" (not a real DocumentFragment yet) > > into something I can insert into the master > > > > there isn't really a copyNode(deep) or insertFragment(node) is > there... > > Creating a DOMDocumentFragment and inserting it into the document using > the standard > append*/insert* methods should do the trick for you. > > http://xmljs.sourceforge.net/website/documentation-w3cdom-DOMDocument.ht > ml#DOMDocumentCreateDocumentFragment > > David > > > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://productguide.itmanagersjournal.com/ > _______________________________________________ > xmljs-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmljs-users > |
From: David J. <dj...@ya...> - 2004-12-16 06:06:09
|
> copy a node (and it's children) from one xml doc (arriving on the page > via xmlhttprequest) to another (the master already created in the page). I think herein lies my confusion. I was focusing too much on the DocumentFragment part. ImportNode is really the appropriate method to be calling for what you're trying to do. > yeah, that was the only way I could get it to work - but work it does! Yea! > thanx for your help, David always a pleasure > I'm using '.getAttribute(name)' elsewhere in the code but saw > 'getAttributeNode(name)' in the docs. Are they interchangable? Not directly... getAttributeNode breaks down to DOMElement.prototype.getAttributeNode = function DOMElement_getAttributeNode(name) { // delegate to DOMNamedNodeMap.getNamedItem return this.attributes.getNamedItem(name); }; getAttribute breaks down to DOMElement.prototype.getAttribute = function DOMElement_getAttribute(name) { var ret = ""; // if attribute exists, use it var attr = this.attributes.getNamedItem(name); if (attr) { ret = attr.value; } return ret; // if Attribute exists, return its value, otherwise, return "" }; So getAttributeNode gives you a node object while getAttribute will give you the node object's value, or "" if the query can't find what you're looking for. Best regards, David |
From: C W. <jeo...@ag...> - 2005-01-03 16:21:42
|
The FAQ says: XML for <SCRIPT> has been tested to work with Netscape, Mozilla, Konqueror, Safari, Opera and Internet Explorer. - http://xmljs.sourceforge.net/website/documentation-faq.html Has anyone tried Netscape 4.7x? Or is this just referring to 6+? |
From: David J. <dj...@ya...> - 2005-01-03 19:48:24
|
Hello! The classic DOM has been tested and will work on Netscape 4.x (and IE 4.x for that matter) but the w3cdom will not (it uses try/catch all over the place). There's even a small classic dom sample code snippit especially for 4.x browsers here: http://xmljs.sourceforge.net/website/sampleApplications-classicdom.html There is a decent possibility that the sax parser will work on generation 4 browsers (it does not use try/catch), but it was not tested. Best regards, David --- C Wilks <jeo...@ag...> wrote: > The FAQ says: > > XML for <SCRIPT> has been tested to work with Netscape, Mozilla, Konqueror, > Safari, Opera and Internet Explorer. > - http://xmljs.sourceforge.net/website/documentation-faq.html > > > Has anyone tried Netscape 4.7x? Or is this just referring to 6+? > > > > > ------------------------------------------------------- > The SF.Net email is sponsored by: Beat the post-holiday blues > Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. > It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt > _______________________________________________ > xmljs-users mailing list > xml...@li... > https://lists.sourceforge.net/lists/listinfo/xmljs-users > |
From: David J. <dj...@ya...> - 2004-12-13 16:14:36
|
> the xmlhttprequest *has* to be there - it's providing lookup data that gets displayed in a form > for editing (think remote procedure calls). There's no reason why you can't use xmlhttprequest and XML for <SCRIPT> at the same time, is there? It should be possible to use xmlhttprequest and simply insert the resulting xml string from the request object into an XML for SCRIPT DOM object. Standardizing on a single DOM Implementation should get you past this and will likely prevent a whole host of other problems later. Since the API of the two dom objects should be pretty much the same, it shouldn't even require much (if any) rework on your part. You could also look into the xmlIO functions of XML for <SCRIPT> to get your XML String from the server and do your RMI. However, if you're using browsers that you know support xmlhttprequest, I'll be the first to admit that object does provide a more robust API and less hoops to jump through. > > As each lookup happens I have to store the previous changes somewhere (the master doc?) and then > post that as one hidden field back to the server for processing. The master doc basically > provides a new root node and some id attributes, ready to be filled with child nodes from the > xmlhttprequest doc. > Again, the master doc should just be an XML for SCRIPT DOM object > now I'm really stuck. any ideas on how I can aggrigate the results of each lookup (ie: add > nodes) to send back to the server in one hidden form field? looks like the data island idea > won't work.... xmlhttprequest should be fine here, as long as you use it just for data retrieval. If you're talking xml data islands (the IE proprietary thing) I think maybe you're making things harder for yourself than you have to. Is there some reason you can't post some simple source code to help us help you out? A very simple recreation that outlines what you're trying to do will go a long way in helping us understand your environment. > > (in panic mode) > Don't panic, find your towel and post some source code :) David |
From: James S. E. <jam...@co...> - 2004-12-14 05:05:42
|
Barry, Try dumping the DOM obtained via XmlHttpRequest to an XML string and then loading the XML into a new document in <XML for Script> to get it into the proper implementation. ;) Thanks, James At 10:14 AM 12/13/2004, you wrote: > > the xmlhttprequest *has* to be there - it's providing lookup data that > gets displayed in a form > > for editing (think remote procedure calls). > >There's no reason why you can't use xmlhttprequest and XML for <SCRIPT> at >the same time, is >there? It should be possible to use xmlhttprequest and simply insert the >resulting xml string from >the request object into an XML for SCRIPT DOM object. Standardizing on a >single DOM Implementation >should get you past this and will likely prevent a whole host of other >problems later. Since the >API of the two dom objects should be pretty much the same, it shouldn't >even require much (if any) >rework on your part. > >You could also look into the xmlIO functions of XML for <SCRIPT> to get >your XML String from the >server and do your RMI. However, if you're using browsers that you know >support xmlhttprequest, >I'll be the first to admit that object does provide a more robust API and >less hoops to jump >through. > > > > > As each lookup happens I have to store the previous changes somewhere > (the master doc?) and then > > post that as one hidden field back to the server for processing. The > master doc basically > > provides a new root node and some id attributes, ready to be filled > with child nodes from the > > xmlhttprequest doc. > > > >Again, the master doc should just be an XML for SCRIPT DOM object > > > now I'm really stuck. any ideas on how I can aggrigate the results of > each lookup (ie: add > > nodes) to send back to the server in one hidden form field? looks like > the data island idea > > won't work.... > >xmlhttprequest should be fine here, as long as you use it just for data >retrieval. If you're >talking xml data islands (the IE proprietary thing) I think maybe you're >making things harder for >yourself than you have to. > >Is there some reason you can't post some simple source code to help us >help you out? A very simple >recreation that outlines what you're trying to do will go a long way in >helping us understand your >environment. > > > > > (in panic mode) > > > >Don't panic, find your towel and post some source code :) > >David |