BizTalk Utilities CV ,   Jobs ,   Code library
 
Home Page


Add/Edit your code items
Search the code library
Browse for the code library


Java and the XML DOM
Having good SAX with Java
JAWAP: the Java Application Framework
WAP Security
Building a WML Application with Enhydra
WML Applications using JavaServer Pages (JSP)
XML Tools for Information Appliances
Interactive Java & XML online tutorial
Information on James Clark's XT (SAX parser)
A list of parsers
Java and XSLT: XSLT Processing with Java
Programming Web Services with XML-RPC: Client-Server Communication
Java and XML: SOAP
30 page javax.xml package class reference
The org.w3c.dom.ProcessingInstruction Interface
The org.xml.sax.XMLReader Interface
org.xml.sax.XMLFilter Interface
org.xml.sax.Locator Interface
org.xml.sax.HandlerBase Handler
org.xml.sax.ext.LexicalHandler Handler


 
 

<< XSLT.NET and XML >>
 


By vivek raut
SOA, Web Services, J2EE, Java, Mainframe, jDeveloper, Eclipse, Oracle AS, Oracle ADF, Oracle Service Registry, Aqualogic Service Registry, Aqualogic Enterprise Repository, SunOne AS, Weblogic, Axis, Netonomy, BPEL, SOAPUI, XML, SOA Governance
First Posted 09/12/2008
Times viewed 324

Parsing a WSDL Effectively


WSDL is an XML format for describing network services as a set of endpoints operating on messages containing either document oriented or procedure-oriented information.

As WSDL contains interface definition, it is sometimes required to extract this useful information.

 

Constituents of a WSDL are:

 

Types uses the XML schema language to declare complex data types and elements that are used elsewhere in the WSDL document.

Import is similar to an import element in an XML schema document; it's used to import

WSDL definitions from other WSDL documents.

Message describes the message's payload using XML schema built-in types, complex types, or elements that are defined in the WSDL document's types element, or defined in an external WSDL document the import element refers to.

portType andOperation describe a Web service's interface and define its methods. A portType and its operation elements are analogous to a Java interface and its method declarations. An operation element uses one or more message types to define its input and output payloads.

Binding assigns a portType and its operation elements to a particular protocol (for instance, SOAP 1.1) and encoding style.

Service is responsible for assigning an Internet address to a specific binding.

Documentation explains some aspect of the WSDL document to human readers. Any of the other WSDL elements may contain documentation elements.

 

The following parsers are generally used for XML parsing and as a WSDL file is also in XML format, these parsers are normally used for parsing.

 

DOM or Document Object Model is a Java API that models XML documents as trees of objects.

It contains objects that represent elements, attributes, values, and so on. DOM is used a lot in situations where speed and memory are not factors, but complex manipulation of XML documents is required.

 

SAX or Simple API for XML differs from DOM in it’s functionality. When a SAX parser

reads an XML document, it fires events as it encounters start and end tags, attributes, values, etc. You can register listeners for these events, and they will be notified as the SAX parser detects changes in the XML document it is reading.

 

As a WSDL’s constituents are well-defined already, it is feasible to use a parser that can get the elements of the WSDL using APIs that are already defined. This will minimize complexity in the code and will help in achieving better performance.

 

Oracle WSDL parser is one such option.

 

It is only needed to import the necessary classes as the APIs are already defined and packaged with wsdl.jar.

 

import oracle.wsdl.WSDLDocument;

import oracle.wsdl.internal.Binding;

import oracle.wsdl.internal.Definitions;

import oracle.wsdl.internal.Documentation;

import oracle.wsdl.internal.Import;

import oracle.wsdl.internal.Message;

import oracle.wsdl.internal.PortType;

 

WSDLDocument wsdldoc = new WSDLDocument(wsdl_url);

Definitions definition = wsdldoc.getDefinitions();

 

Map servicesMap = definition.getServices();

 

Map bindingsMap = definition.getBindings();

 

Map ptypesMap = definition.getPortTypes();

 

Map messagesMap = definition.getMessages();

 

Map importsMap = definition.getImports();

 

Documentation docs = definition.getDocumentation();

 

As there can be multiple elements, an iterator can be used to parse an individual element.

For Example:

 

Iterator iterator = servicesMap.entrySet().iterator();

        while (iterator.hasNext()) {

            Map.Entry me = (Map.Entry) iterator.next();

            …….

        }

 

JWSDL is another option that is intended for use by developers of Web services tools and others who need to utilize WSDL documents in Java.

JWSDL is designed to allow users to read, modify, write, create and re-organize WSDL documents in memory. JWSDL is not designed to validate WSDL documents beyond syntactic validity. One use of JWSDL is to develop a tool that validates WSDL semantically.

JWSDL is designed for use in WSDL editors and tools where a partial, incomplete or incorrect WSDL document may require representation.

 

Details of JWSDL can be obtained by accessing the following link:

 

http://wsdl4j.sourceforge.net/downloads/JSR110_proposed_final_draft.pdf

Rate this article on a scale of 1 to 10 (1 votes, average 10)

Your vote :  

<< XSLT.NET and XML >>
 





Leave a comment for this article
Your name
Your email (optional)
Your comment
Optional: Upload an attachment
Enter the code shown:

 
 

    Email TopXML