• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

getting child elements(with values) from xml

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 825
5
Python Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic