How can I use Nant's xmlpoke target to remove a node

后端 未结 2 442
失恋的感觉
失恋的感觉 2021-02-07 10:52

Given the following xml:


   Content A
   Content A
<         


        
2条回答
  •  滥情空心
    2021-02-07 11:50

    xmlpeek only reads values. xmlpoke only sets values. Unfortunately, nant does not have an xmldelete task.

    I solved this issue by creating a nant in a nant file I can easily re-use between project.

    I chose to leverage nant's built-in , , and tasks.

    Advantages:

    • Works with regular expression (see disadvantages).
    • Can match any text, including XML!

    Disadvantages:

    • Have you ever solved a problem with a regex? If yes, you now you have another problem!
    • The regex value in the nant file MUST be escaped! (Use an online xml escaper tool).
    
    
    
        
    
            
            
            
            
    
        
    
    
    

    Below is how to include and call this target. Keep in mind the all the parameters are global and must be defined before calling the target.

    • delete.from.file.path: the path of the file to be modified.
    • delete.from.file.regex: the regex matching what to removed (and defining BEFORE and AFTER groups).
    
    
        
    
        
    
            
            
            
    
        
    
    
    
    

提交回复
热议问题