Someone told me that groovy xml parser is better and easy, my question how to use groovy inside java to parse an xml file and put it in a pojo object ? thanks.
-
Do you want to use groovy just to do this? Did you try to use another parser? – davidbuzatto Jul 29 '12 at 05:34
-
I would like to see how to use this groovy parser inside java.yes for now I want it just for this. – Majid Kamal Jul 29 '12 at 05:47
-
If you want to use it just for parsing, I think that you should use a parser writen in Java as [SimpleXML](http://simple.sourceforge.net/) or [XStream](http://xstream.codehaus.org/). I already used both, but I think that SimpleXML is much better because it is simpler than XStream. – davidbuzatto Jul 29 '12 at 06:06
-
where can I see an example of SimpleXML parsing an xml and put it in an object ? – Majid Kamal Jul 29 '12 at 06:11
-
There are lots of tutorials in its site. Didn't you saw? http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php – davidbuzatto Jul 29 '12 at 06:16
-
You'll find many flavors of parsing xml in java via groovy [here][1] [1]: http://stackoverflow.com/questions/12690794/xml-parsing-in-java-via-groovy/12690795 – Arham Oct 02 '12 at 14:18
1 Answers
Groovy compiler has a feature called "joint-compilation". That is used for compiling groovy project with another java project. It is defined in their site as
Joint compilation means that the Groovy compilation will parse the Groovy source files, create stubs for all of them, invoke the Java compiler to compile the stubs along with Java sources, and then continue compilation in the normal Groovy compiler way. This allows mixing of Java and Groovy files without constraint.
But the catch is as your project's codebase increases, it causes some problems with static references. If you are compiling your code using Maven or use Ant scripts then life becomes easier.
Ref Link : http://groovy.codehaus.org/The+groovyc+Ant+Task
You could also look into this link http://today.java.net/pub/a/today/2004/08/12/groovyxml.html where the user has tried a lot of options including Groovy.

- 2,295
- 1
- 14
- 17