Subject: RE: [xsl] MSXML3: Getting the new node object after .replaceChild From: "Chris Bayes" <Chris@xxxxxxxxxxx> Date: Fri, 13 Apr 2001 20:40:50 +0100 |
Joel, This works fine <%@ LANGUAGE=VBScript %> <html> <body> <% stop set xml = CreateObject("Microsoft.XMLDOM") xml.loadXML("<test><child/></test>") set anynode = xml.selectSingleNode("/test/child") set newnode = xml.createNode(1 ,"newChild", "") set oldnode = anynode.parentNode.replaceChild(newnode, anynode) %> newnode xml is <%=response.write(newnode.xml)%> oldnode xml is <%=response.write(oldnode.xml)%> document xml is <%=response.write(xml.xml)%> </body> </html> If you do a view source you will get <html> <body> newnode xml is <newChild/> oldnode xml is <child/> document xml is <test><newChild/></test> </body> </html> Which shows that newnode is still a valid node after replacing the old node. When you do this nodeParent.replaceChild xmlDocNew.documentElement, nodeToReplace you are inserting the document element under the parent not a new node Ciao Chris XML/XSL Portal http://www.bayes.co.uk/xml >-----Original Message----- >From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx >[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Joel P >Thornton >Sent: 13 April 2001 19:27 >To: Xsl-List >Subject: [xsl] MSXML3: Getting the new node object after .replaceChild > > >I have a question relating specifically to using MSXML3, under VBScript >(ASP). > >What I want to do is this: replace a given node with a new node, >and then do >something with that new node. However, I am having a problem here, because >I can't find a way to (elegantly) use that new node after I execute a >replaceChild() on the parent node. replaceChild() returns the *old* node, >but I need to use the *new* node. And after I have added the new >node to the >parent, that node object gets cleared out, so I can't use it anymore. > >The only way I'm finding to accomplish this is to first do replaceChild(), >then use selectSingleNode() to find the newly added node of the parent in >question, and work with that. This is really a workaround, and I'm >wondering if there is a better way to do this, so I can just USE the new >node after executing replaceChild(). > >Here's the code that won't work as I want it to: > >... >Set xmlDocNew = getContentXML("1") >nodeToReplace.parentNode.replaceChild xmlDocNew.documentElement, >nodeToReplace > >** at this point, nodeNew is just an empty XML document, its contents being >moved into parentNode's kids. ** >... > > > >Here's the workaround I am using but want to improve upon: > >... >Set xmlDocNew = getContentXML("1") >Set nodeParent = nodeToReplace.parentNode >nodeParent.replaceChild xmlDocNew.documentElement, nodeToReplace >Set nodeDesired = >nodeParent.selectSingleNode("ContentNode[@content_id='1']") >... > >As you can see this is really not ideal ;) Aside from being a hack job, it >requires I know how to identify the node in advance >("ContentNode[@content_id='1']"), which is just more of a hack as far as I >can see. > > >Any suggestions most appreciated!! > >joel > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] MSXML3: Getting the new node , Joel P Thornton | Thread | RE: [xsl] MSXML3: Getting the new n, Joel P Thornton |
[xsl] MSXML3: Getting the new node , Joel P Thornton | Date | Re: [xsl] xslisapi filter for iis, bill french |
Month |