XmlSlurper in Groovy

This class belongs to the  package groovy.util.XmlSlurper. The XmlSlurper is very useful in groovy to handle XML related operations


The constructor XmlSlurper() can be used to create a very loose (non-validating and namespace-aware) instance.

XmlSlurper parsers
The parse method has many flavors. The parse method returns a GPathResult object.

parse(File file) : XML file can be parsed directly
parse(InputSource input) : Parse the content of input source
parse(InputStream input) : Any binary input stream which refers to XML
parse(Reader in): Using a Reader instance
parse(String uri): URI eg: http://www.helicaltech.com/test.xml
parseText(String text): A helper method to parse the given text as XML


This is the key object which helps in navigating the xml object parsed by XmlSlurper

Some important method of the GPathResult
breadthFirst(): Provides an Iterator over all the nodes using a breadth-first traversal.
childNodes(): Returns an iterator over the child nodes
children(): Returns the children of this GPathResult as a GPathResult object.
declareNamespace(Map newNamespaceMapping): Adds the specified map of prefix to namespace mappings to this GPathResult.
depthFirst() :Provides an Iterator over all using depth-first traversal.
find(Closure closure) :Returns the first child matching the condition(s) specified in the passed closure.
name(): Returns the name of element
parent(): Returns as parent nodes
size() : Returns the size of this GPathResult.
text(): Returns the text of this GPathResult as a String.




Start With SOAP

SOAP stands for Simple Object Access Protocol.SOAP is a protocol for accessing web services.SOAP is based on XML.

What is SOAP?

  • SOAP is a communication protocol
  • SOAP is for communication between applications
  • SOAP is a format for sending messages
  • SOAP communicates via Internet
  • SOAP is platform independent
  • SOAP is language independent
  • SOAP is based on XML
  • SOAP is simple and extensible

SOAP allows you to get around firewalls



It is important for application development to allow Internet communication between programs.

Today’s applications communicate using Remote Procedure Calls (RPC) between objects like DCOM and CORBA, but HTTP was not designed for this. RPC represents a compatibility and security problem; firewalls and proxy servers will normally block this kind of traffic.

A better way to communicate between applications is over HTTP, because HTTP is supported by all Internet browsers and servers. SOAP was created to accomplish this.

SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages

SOAP Building Blocks

A SOAP message is an ordinary XML document containing the following elements:

  • An Envelope element that identifies the XML document as a SOAP message
  • A Header element that contains header information
  • A Body element that contains call and response information
  • A Fault element containing errors and status information

All the elements above are declared in the default namespace for the SOAP envelope:

Syntax Rules

Here are some important syntax rules:

  • A SOAP message MUST be encoded using XML
  • A SOAP message MUST use the SOAP Envelope namespace
  • A SOAP message MUST use the SOAP Encoding namespace
  • A SOAP message must NOT contain a DTD reference

A SOAP message must NOT contain XML Processing Instructions.


<?xml version="1.0"?>

By Prashansa Kumari