How to remove a specific node in omnixml delphi

I have read this answer , but I do not know how to use this sample in my case. I have 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 remove Node with PN = BBBB?


I'm sorry, I think I don't understand in my question, My question is how to remove this section:

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

      

not only this section

<PN>BBBB</PN>

      


Answer: Thanks to Runner, I changed his code a little

  DeleteNode := XMLDoc.DocumentElement.SelectSingleNode('/Archive/DataList/Data[PN="BBBB"]');
  DeleteNode.ParentNode.RemoveChild(DeleteNode);

      

+3


source to share


1 answer


One of the methods:

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

      

You can search for it in any other way. Please note that in the above example, only the first node event will be displayed. But I recommend you look at SimpleStorage



It is a set of interfaces that make working with OmniXML much easier. The above example:

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

      

SimpleStorage also simplifies just about every other aspect of using OmniXML and XML in general.

+5


source







All Articles