[xsl] MSXML3: Getting the new node object after .replaceChild

Subject: [xsl] MSXML3: Getting the new node object after .replaceChild
From: "Joel P Thornton" <joelt@xxxxxxxxxxxxx>
Date: Fri, 13 Apr 2001 11:27:00 -0700
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


Current Thread