3

i've read this answer but i don't know how to use that sample in my case. I have an xml file

 <Archive>                                  
  <Source>                               
     <Name>321</Name>                   
     <BatchID>123</BatchID>    
  </Source>                              
  <DataList>                             
     <Data>            
        <PN>AAAA</PN>
        <FN>1111</FN>
     </Data>
     <Data>            
        <PN>BBBB</PN>
        <FN>2222</FN>
     </Data>
  </DataList>                            
</Archive>

How can i delete the Node that has PN=BBBB?


I'm so sorry, i think i'm not clear in my question, my bad, My Question is how to delete this section:

 <Data>            
    <PN>BBBB</PN>
    <FN>2222</FN>
 </Data>

not only this section

<PN>BBBB</PN>

The Answer: Thanks to Runner, i modified a little bit of his code

  DeleteNode := XMLDoc.DocumentElement.SelectSingleNode('/Archive/DataList/Data[PN="BBBB"]');
  DeleteNode.ParentNode.RemoveChild(DeleteNode);
Community
  • 1
  • 1
Erwan
  • 202
  • 3
  • 10

1 Answers1

5

One way:

  DeleteNode := OmniXML.DocumentElement.SelectSingleNode('//[PN=''BBBB'']');
  DeleteNode.ParentNode.RemoveChild(DeleteNode);

You can search for it any other way. Note that the above example will only select first node occurence. But I recommend you look at SimpleStorage

This is a set of interfaces that greatly simplify working with OmniXML. The above example would then be:

SimpleStorage.Remove('//[PN=''BBBB'']');

SimpleStorage also simplifies almost every other aspect of using the OmniXML and XML in general.

menjaraz
  • 7,551
  • 4
  • 41
  • 81
Runner
  • 6,073
  • 26
  • 38
  • 1
    You should also disclose in the post that you are its author ;-) – menjaraz Mar 23 '12 at 07:54
  • Eh, it does not give any additional value to the answer ;) – Runner Mar 23 '12 at 07:55
  • You are right, Simple Storage (I keep promoting it) and your post are all OK but we must also consider this [section](http://stackoverflow.com/faq#promotion) of the FAQ. Thank you again for sharing. – menjaraz Mar 23 '12 at 08:02
  • Thanks for support. The only reason why I mention SimpleStorage in my answers is because it can help a lot working with XML. And a lot of people do not know about it because it is not mentioned on the OmniXML site. – Runner Mar 23 '12 at 08:25
  • Primoz is your first promoter (Cromis.SS I mean) I knew: He never missed the opportunity to suggest people to use SS or GpFluentXML on top of OmniXML. Cromis.AnyValue and Cromis.Threading units are even in the OmniThreadLibrary ditribution under \bag of stuff\tmonitor-vs-commqueue. Thanks to him, I came across Cromis.SS. – menjaraz Mar 23 '12 at 08:39
  • I know Primoz, he is a great programmer and a big person :) Ah that other units are part of his queue test. We had a little competition. – Runner Mar 23 '12 at 08:56
  • Thanks Runner, i'll take a look at SimpleStorage – Erwan Mar 24 '12 at 11:28