Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML DOM removeChild

Status
Not open for further replies.

psychospiller

Technical User
Jan 30, 2005
1
GB
I am trying to remove specific items from an XML file via ASP and the MS XML DOM but I cant seem to reference the items correctly. The XML structure is fixed so i cant change that but could someone explain to me how to remove a specific <asset> child from the XML below, by using its the asset node's 'id' attribute as a reference ? Thanks

<project>
<folder id="1">
<asset id="99" />
<asset id="100" />
</folder>
<folder id="2">
<asset id="101" />
<asset id="102"><details title="test" /></asset>
</folder>
</project>
 
Use xpath:

Code:
set node = xml.selectSingleNode("//asset[@id='101']")
set theparent = node.parentNode
theparent.removeChild(node)
 
yup,

You can also simplify it to:
set node = xml.selectSingleNode("//asset[@id='101']")
node.parentNode.removeChild(node)


Another way to remove a node is to move it to a seperate DOM... you can set up an undo method this way ;-)
xml2.documentElement.appendChild(xml.selectSingleNode("//asset[@id='101']"))

On the other hand, if you actually want to COPY the node to a different location, you must use the Clone method...
xml2.documentElement.appendChild(xml.selectSingleNode("//asset[@id='101']")).Clone(True)


Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top