Forum Discussion
gregory_kozel
16 years agoNew Contributor
Hi Shonzilla, Thank you for the response.
As I do not have Pro at the moment, I am trying to think up other ways to generate the XML. At this point I feel as though it can be done using Groovy to read in a flatfile of name=value pairs, parse out the name=value pairs, and build the XML via importing groovy.xml.MarkupBuilder.
Since I am shifting gears more on the XML builder aspect of things, here is the code I'm starting with:
With this code, filename.xml is simply a list of XML tags with the respective values in each tag. So if we take my example above, a flatfile with name=value pairs of:
field1=1
field2=2
field3=3
field1=4
field2=5
field3=6
would generate the following:
1
2
3
4
5
6
I would need some way to get the following xml output:
1
2
3
4
5
6
I am new to this (only started playing with this last week). Perhaps a better question would be, is there a comprehensive "using Groovy to build XML" guide out there I can start reading?
Again, Thank you very much for your patience and assistence.
~Greg
As I do not have Pro at the moment, I am trying to think up other ways to generate the XML. At this point I feel as though it can be done using Groovy to read in a flatfile of name=value pairs, parse out the name=value pairs, and build the XML via importing groovy.xml.MarkupBuilder.
Since I am shifting gears more on the XML builder aspect of things, here is the code I'm starting with:
import groovy.xml.MarkupBuilder
def writer = new StringWriter()
def xml = new MarkupBuilder( writer )
def list = []
new File("filename.txt").eachline { line -> list.add( line ) }
context.setProperty( "values", list )
context.setProperty( "index", 0 )
def values = context.getProperty( "values" )
def index = context.getProperty( "index" )
while( index < values.size() ) {
def str = values[index]
def parseValue = str.indexOf( "=" )
def nextValueName = str.substring( 0, parseValue )
def nextValue = str.substring( parseValue+1 )
xml."$nextValueName"( nextValue )
index++
}
outPath = "filename.xml"
outFile = new File( outPath )
outFile << writer
With this code, filename.xml is simply a list of XML tags with the respective values in each tag. So if we take my example above, a flatfile with name=value pairs of:
field1=1
field2=2
field3=3
field1=4
field2=5
field3=6
would generate the following:
I would need some way to get the following xml output:
I am new to this (only started playing with this last week). Perhaps a better question would be, is there a comprehensive "using Groovy to build XML" guide out there I can start reading?
Again, Thank you very much for your patience and assistence.
~Greg
Related Content
- 4 years agokrasnoludpauli
- 2 years agovericomms
Recent Discussions
- 6 days agoemoya