efficiently removing duplicate xml elements in c#

前端 未结 3 998
天命终不由人
天命终不由人 2020-12-22 01:20

I have couple of XML files that contain lots of duplicate entries, such as these.


  

        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-22 01:40

    If your duplicates are always in this form, then you could do this with a bit of XSLT to remove duplicate nodes. The XSLT for this is:

    
      
        
          
        
      
    
      
    
    

    If it's something that can happen frequently, then it might be worth having that stylesheet loaded into a XslCompiledTransform instance.

    Or you can simply get a list of all duplicate nodes using this XPath:

    /annotations/annotation/image[@location = preceding-sibling::image/@location]
    

    and remove them from their parent.

提交回复
热议问题