XML DOM: selecting nodes and deleting them

wxdqz

New Member
I am using the MSXML 2.0 parser and the VB6 XML DOM. I am try to select nodesinto a nodelist wherethe second col's value (<Col idx="2">) is 2. I want to delete this nodelist node by node using a loop. I have sort of got it working but it willleave the rec tags behind and delete the children. How can I select therecords so that when I delete them using removeChild(), the whole record(<Rec>, <Cols>, and the 8 <Col> tags) will be gone?Here is my XML file:<Table name="Vectors"><Recs><Rec pkey="1|2|3|"><Cols><Col idx="1">2</Col><Col idx="2">3</Col><Col idx="3">2</Col><Col idx="4"></Col><Col idx="5">-1</Col><Col idx="6">-1</Col><Col idx="7">-1</Col><Col idx="8">-1</Col></Cols></Rec><Rec pkey="1|3|2|"><Cols><Col idx="1">3</Col><Col idx="2">2</Col><Col idx="3">2</Col><Col idx="4"></Col><Col idx="5">-1</Col><Col idx="6">-1</Col><Col idx="7">-1</Col><Col idx="8">-1</Col></Cols></Rec><Rec pkey="1|3|3|"><Cols><Col idx="1">3</Col><Col idx="2">3</Col><Col idx="3">2</Col><Col idx="4"></Col><Col idx="5">-1</Col><Col idx="6">-1</Col><Col idx="7">-1</Col><Col idx="8">-1</Col></Cols></Rec></Recs></Table>Here is my VB code:searchString = "Table[@name='Vectors']/Recs/Rec" & _"[.//Col[@idx = '2' and text() = '2']]"Set delList = xmlDoc.selectNodes(searchString)delListLength = delList.lengthdelList.Reset'Delete vector valuesFor i = 0 To delListLength - 1Set node = delList.nextNodeSet oldNode = node.removeChild(node.childNodes.nextNode)Next iThis code will leave<Rec pkey="1|2|2|"></Rec>and<Rec pkey="1|3|2|"></Rec>I tried only selecting up to <Recs> in the searchString and put a conditionon recs but it returned all of the records instead of the two with<Col idx="2">2</Col>.If anyone can figure this out...PLEASE help me! It will be greatly appreciated.Thanks in advance!Mark DempseyInternational Technegroup Inc.
 
Back
Top