• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to write XML to a new file.  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can easily generate XML with groovy and output it to the groovy console.

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.gpx() { wpt(lat:’22.22222’, lon:’77.77777’) }
println writer.toString()

I also know how to create a new file.

def target ="C:/gps.xml"
File file= new File(target)

But how do I write the XML to a new file called gps.xml..?

Thanks in advanced.
 
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There has to be an easier way (but I can't find the example), but this should work:

 
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your file object has both write() and append() methods that accept a string. write() replaces the file contents while append() just adds to it.
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!