Monday, August 1, 2011

Groovy WSDL Parser

class PVWSDLParser {
 public static void main(String[] args) {
  PVWSDLParser parser = new PVWSDLParser();
  parser.parse("/path/to/your.wsdl");
 }
 
 public void parse(String filename) {
  
  def nsxsd = new groovy.xml.Namespace("http://www.w3.org/2001/XMLSchema", 'xsd')
  def nswsdl = new groovy.xml.Namespace("http://schemas.xmlsoap.org/wsdl/", 'wsdl')
  
  def wsdlDocument = new XmlParser().parse(new File(filename));
  def targetNamespace = wsdlDocument.'@targetNamespace';
  
  def imports = wsdlDocument[nswsdl.types][nsxsd.schema][nsxsd.import];
  imports.each { theimport ->
   System.out.println(theimport.'@schemaLocation');  
   System.out.println(theimport.'@namespace');
  } 
 }
}



A LOT easier than in Java!

No comments: