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 |