This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Groovy and the fly likes getting child elements(with values) from xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "getting child elements(with values) from xml" Watch "getting child elements(with values) from xml" New topic
Author

getting child elements(with values) from xml

Rakshit Achary
Greenhorn

Joined: Dec 20, 2012
Posts: 2
Dear Members,

I am completely new to groovy scripting and struggling lot to get my work done. Kindly help me to resolve the below scenario.
I have soap request as below.



I need to traverse through this soap request and extract elements which will be assigned some values. (I am sorry, I am not well known of xml namings for its nodes/elements.). For example, my groovy code should yieldfollowing result



I have in my soap request more than 10 iterations for File. So, I have used #number. Please do help me at the earliest so that I can be saved from ire I am facing .

Thanks in advance

Rakshit
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

The topic is little bit too much for the beginning level, so I moved it to more appropriate forum.

Welcome to the Ranch and good luck with your question!


The quieter you are, the more you are able to hear.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

Have you looked at the XmlSlurper class in Groovy?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rakshit Achary
Greenhorn

Joined: Dec 20, 2012
Posts: 2
Thanks Kemal ,

Mark, I have surfed on the internet many examples (both in groovy and java) for the same but not able to reach to a conclusion owing to my less knowledge about both.

Can you please help me by providing same in both language codes (java and groovy).

Regards
Rakshit
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1658
    
  14

Rakshit Achary wrote:I have surfed on the internet many examples (both in groovy and java) for the same but not able to reach to a conclusion owing to my less knowledge about both.

It's simple: use Groovy's XmlSlurper to read and parse XML as it's Groovy (not Java) and it's much easier to use.

  • Here is a tutorial on Groovy and XML by Scott Davis (a keen Groovy advocate). It's from 2009 so the latest version of the XmlSlurper may be slightly different.
  • Here is a short example of using XmlSlurper.
  • Here is a very brief comparison of using XmlSlurper and Java to process the same snippet of XML.

  • Just try it out on your XML - you'll probably find you can solve your problem even quicker than asking the question here on JavaRanch!


    No more Blub for me, thank you, Vicar.
     
    wood burning stoves
     
    subject: getting child elements(with values) from xml