Posted By

jsbournival on 09/14/07


Tagged

groovy dom4j


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ingorichter
doctorillo


Modifying XML file structure (Groovy)


 / Published in: Groovy
 

URL: http://www.dom4j.org/guide.html

  1. import org.dom4j.io.*
  2. import org.dom4j.*
  3.  
  4. new File('in/emissions').eachFile{ file ->
  5.  
  6. if (!file.name.endsWith('.xml'))
  7.  
  8. def emission = new SAXReader().read(file).rootElement
  9.  
  10. def sondage = emission.addElement('pr:sondage')
  11. sondage.addAttribute('xsi:nil', 'true')
  12. sondage.setText('n/a')
  13.  
  14. def writer = new FileWriter('out/' + file.name)
  15. XMLWriter output = new XMLWriter(writer, OutputFormat.createPrettyPrint())
  16.  
  17. output.writeNode(emission)
  18. output.close()
  19. }

Report this snippet  

You need to login to post a comment.