Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting child elements(with values) from xml

 
Rakshit Achary
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you looked at the XmlSlurper class in Groovy?

Mark
 
Rakshit Achary
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic