简体   繁体   中英

How to delete specific node in omnixml delphi

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);

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM