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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML DOM - How do I delete a node? 2

Status
Not open for further replies.

ftpdoo

Programmer
Aug 9, 2001
202
GB
Hi,

I have an XML DOM built up in memory:

<WorkOrder>
<Script>
<Code>MLT05</Code>
<Mandatory>MANDATORY</Mandatory>
<Status>Not Started</Status>
<StatusCode>NS</StatusCode>
<Description>Work Order</Description>
<FileName/>
<FileLocation/>
<ResultSetName/>
</Script>
<Script>
<Code>MLT07</Code>
<Mandatory>MANDATORY</Mandatory>
<Status>Not Started</Status>
<StatusCode>NS</StatusCode>
<Description>Reinstatment</Description>
<FileName/>
<FileLocation/>
<ResultSetName/>
</Script>
</WorkOrder>

I want to delete one of the script nodes ie delete the second one for example:


<Script>
<Code>MLT07</Code>
<Mandatory>MANDATORY</Mandatory>
<Status>Not Started</Status>
<StatusCode>NS</StatusCode>
<Description>Reinstatment</Description>
<FileName/>
<FileLocation/>
<ResultSetName/>
</Script>

How would I do this?? Any ideas?

Any help would be much appreachiated
Jonathan
 
Try:

Code:
' Assume MyDom contains the DOM Document
Dim MyElem as MSXML2.IXMLDOMElement

Set MyElem = MyDom.DocumentElement.SelectSingleNode("Script[Code='MLT07']")

The search expression uses the XPath syntax and will select the first Script element where its Code element has the value 'MLT07'. You can also walk round the childnodes of the DocumentElement until you find it.


Bob Boffin
 
Thanks..

Then once I've found the item how do I delete it??

JD :)
 
Oops I forgot the line of code to delete the element

Code:
.
.
.

MyDom.DocumentElement.RemoveChild(MyElem)

Bob Boffin
 
MyDom.parentNode.removeChild MyElem

------------------------
Hit any User to continue
 
Thanks guys - that worked brilliantly! :O)

Im going to dish you out some stars now!

Jonny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top