how to delete xml node from xmlnodelist

hi,
i need to delete all “Machining” nodes in this xml_doc

1 0 0 Squadrette_TESTA L - 0 900 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Squadrette_CODA 0 0 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Asola_Drenaggio_Frontale sc_aq2(80, , 3, 2, 0) 0 1 1 Scarichi acquaMIX / Asola_Scarico_Mix_Classico 2 FOMCAM 3 1 0 0 Squadrette_TESTA L - 0 900 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Squadrette_CODA 0 0 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Asola_Drenaggio_Frontale sc_aq2(80, , 3, 2, 0) 0 1 1 Scarichi acquaMIX / Asola_Scarico_Mix_Classico 2 FOMCAM 3

i use this code but it does not work : i get error number 8 ( reference to a non-existent node )

n = xml_doc.XQL("/TIPOLOGIA/AREA/SEGMENTO/Machining")

for i as integer = 0 to n.Length-1

dim nx As XmlNode
nx = n.Item(0)

Call xml_doc.DocumentElement.RemoveChild(nx)

n = n
next

someome can help me?

thanks

Enzo

Try

[code]nlast = n.Length-1

for i as integer = nlast downto 0
try
Call xml_doc.DocumentElement.RemoveChild(nx)
catch
msgbox "no such node… index " + str(i)
end try

next[/code]

Its likely the downto which will fix it, but without checking Im not sure if the range is 0 based or 1 based…

Hi Jeff
unfortunately it doesn’t work, the error is always the same. It goes wrong immediately to the first element that starts from the beginning or from the end as you suggested.
But I see that the code I posted has lost the formatting and may have deceived you.
I try to pass it with the right formatting I hope it is clearer.

Thanks for your interest
Enzo

1 0 0 Squadrette_TESTA L - 0 900 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Squadrette_CODA 0 0 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Asola_Drenaggio_Frontale sc_aq2(80, , 3, 2, 0) 0 1 1 Scarichi acquaMIX / Asola_Scarico_Mix_Classico 2 FOMCAM 3 1 0 0 Squadrette_TESTA L - 0 900 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Squadrette_CODA 0 0 1 0 MIX / Squadretta_Mix_Classico_TESTA 4 FOMCAM 3 Asola_Drenaggio_Frontale sc_aq2(80, , 3, 2, 0) 0 1 1 Scarichi acquaMIX / Asola_Scarico_Mix_Classico 2 FOMCAM 3

how can I post the code without losing the formatting?

This works…

[code]dim xmlndes as xmlnodelist
dim xmlnod as xmlnode
dim xmlnodpar as xmlnode

xmlndes = xml_doc.Xql("//Machining")

for i as integer = xmlndes.Length-1 downto 0

xmlnod = xmlndes.item(i)
xmlnodpar = xmlnod.Parent
xmlnodpar.RemoveChild xmlnod

next

msgbox xmldoc.ToString[/code]

Hi Jeff,
Yes, now it work’s prefectly
thaks you so much for your interest to my problem.
Great!!