Modifying XML file structure (Groovy)


/ Published in: Groovy
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.