vb.net Remove an element from XML

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; <?<span style="color:#A31515; xml <span style="color:Red; version<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1.0<span style="color:Black; " <span style="color:Red; encoding<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; utf-16<span style="color:Black; " <span style="color:Red; standalone<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; yes<span style="color:Black; " <span style="color:Blue; ?>
<span style="color:Blue; <<span style="color:#A31515; orders<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; order <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1190746<span style="color:Black; " <span style="color:Red; datum<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; donderdag 8 april 2010<span style="color:Black; " <span style="color:Red; totaalprijs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 404<span style="color:Black; " <span style="color:Red; rembours<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; product <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Whirlpool hj6556<span style="color:Black; " <span style="color:Red; model<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " aantal="1<span style="color:Black; " <span style="color:Red; barcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; **********<span style="color:Black; " <span style="color:Red; barcode2<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " barcode3="<span style="color:Black; " <span style="color:Red; quantity<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0" locatie="<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; order<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; order <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1191114<span style="color:Black; " <span style="color:Red; datum<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; donderdag 22 september 2011<span style="color:Black; " <span style="color:Red; totaalprijs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1353,9505<span style="color:Black; " <span style="color:Red; rembours<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; product <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; LG 24g4343t<span style="color:Black; " <span style="color:Red; model<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " aantal="1<span style="color:Black; " <span style="color:Red; barcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; **********<span style="color:Black; " <span style="color:Red; barcode2<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " barcode3="<span style="color:Black; " <span style="color:Red; quantity<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0" locatie="<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; order<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; order <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1190914<span style="color:Black; " <span style="color:Red; datum<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; zondag 11 april 2010<span style="color:Black; " <span style="color:Red; totaalprijs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 117,95<span style="color:Black; " <span style="color:Red; rembours<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; product <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Samsung 7865hrh45<span style="color:Black; " <span style="color:Red; model<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " aantal="1<span style="color:Black; " <span style="color:Red; barcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; **********<span style="color:Black; " <span style="color:Red; barcode2<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " barcode3="<span style="color:Black; " <span style="color:Red; quantity<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0" locatie="<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; order<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; order <span style="color:Red; id<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1189651<span style="color:Black; " <span style="color:Red; datum<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; donderdag 25 maart 2010<span style="color:Black; " <span style="color:Red; totaalprijs<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 50,6159<span style="color:Black; " <span style="color:Red; rembours<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0<span style="color:Black; "<span style="color:Blue; >
<span style="color:Blue; <<span style="color:#A31515; product <span style="color:Red; name<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Indesit hj645t646556<span style="color:Black; " <span style="color:Red; model<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " aantal="1<span style="color:Black; " <span style="color:Red; barcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; **********<span style="color:Black; " <span style="color:Red; barcode2<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " barcode3="<span style="color:Black; " <span style="color:Red; quantity<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 0" locatie="<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; <<span style="color:#A31515; afzender <span style="color:Red; bedrijf<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; " naam="E. Someone<span style="color:Black; " <span style="color:Red; straat<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; somestreet 37<span style="color:Black; " <span style="color:Red; postcode<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; 1234 AL<span style="color:Black; " <span style="color:Red; plaats<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; SampleCity<span style="color:Black; " <span style="color:Red; land<span style="color:Blue; =<span style="color:Black; "<span style="color:Blue; Nederland<span style="color:Black; " <span style="color:Blue; />
<span style="color:Blue; </<span style="color:#A31515; order<span style="color:Blue; >
<span style="color:Blue; </<span style="color:#A31515; orders<span style="color:Blue; >
[/code]

Im using VB 2010 Express and i want to remove as example the complete element order id=<span style="white-space:pre 1190914


<span style="white-space:pre how can i do this. The code i tried:

<div style="color:Black;background-color:White; <pre>
orderid = 1190914
<span style="color:Blue; Dim myDoc <span style="color:Blue; As XmlDocument = <span style="color:Blue; New XmlDocument
myDoc.Load(<span style="color:#A31515; "c:XML" + <span style="color:Blue; Date.Now.ToString(<span style="color:#A31515; "dd-MM-yyyy") + <span style="color:#A31515; ".xml")
<span style="color:Blue; Dim myNode <span style="color:Blue; As XmlNode = myDoc.SelectSingleNode(<span style="color:#A31515; "/orders/order[id=" & orderid & <span style="color:#A31515; "]")

<span style="color:Blue; If <span style="color:Blue; Not myNode <span style="color:Blue; Is <span style="color:Blue; Nothing <span style="color:Blue; Then
myNode.ParentNode.RemoveChild(myNode)
myDoc.Save(<span style="color:#A31515; "c:XML" + <span style="color:Blue; Date.Now.ToString(<span style="color:#A31515; "dd-MM-yyyy") + <span style="color:#A31515; ".xml")
<span style="color:Blue; End <span style="color:Blue; If
[/code]
<br/>
The problem is that myNode is always nothing<br/>


<span style="white-space:pre <br/>


View the full article
 
Back
Top