How I can parsing a complex Type? [message #115057] |
Fri, 01 July 2005 09:04  |
Eclipse User |
|
|
|
Originally posted by: andreas140983.libero.it
Hi, I'm using the wsdl4j lbrary and I'm parsing a wsdl file. If I want to
parse the "types" section and extract the complexType how I can do it?
Help me please!!
|
|
|
|
Re: How I can parsing a complex Type? [message #115946 is a reply to message #115155] |
Mon, 04 July 2005 15:13   |
Eclipse User |
|
|
|
Hi Andrea,
The WSDL4J project is actually a sourceforge project. (See
http://sourceforge.net/projects/wsdl4j/.) I believe the Apache project
Arthur is referring to is the Woden incubator project
(http://incubator.apache.org/woden) which is developing a WSDL 2.0 parser.
There is a plan in place to donate the WSDL4J code to the Woden project.
To answer your question, the WTP WSDL validator has the same requirement
as you. To parse the types the validator creates a string representation
of each inline schema (from the DOM element returned from the WSDL4J
model) and parses it using Apache Xerces. Xerces returns an XSModel object
which allows easy access to the elements and types defined in the schema.
The WSDL validator's inline schema validator has an example of parsing the
types (see http://tinyurl.com/9zcgl) and the WSDL 1.1 validator has an
example of accessing the types (see http://tinyurl.com/aauxq).
Specifically the code you're probably insterested in is,
Parsing the schema
------------------
ValidateErrorHandler errorHandler = new ValidateErrorHandler();
errorHandler.getErrorMessages().clear();
try
{
XMLGrammarPreparser grammarPreparser = new XMLGrammarPreparser();
XMLGrammarPool grammarPool = new XMLGrammarPoolImpl();
grammarPreparser.setGrammarPool(grammarPool);
grammarPreparser.setErrorHandler(errorHandler);
try
{
XMLInputSource is = null;
Reader reader = new StringReader(schema);
is = new XMLInputSource(null,filelocation,filelocation,reader,null);
grammarPreparser.registerPreparser(XMLGrammarDescription.XML _SCHEMA,null/*schemaLoader*/);
XMLGrammarLoader schemaLoader =
grammarPreparser.getLoader(XMLGrammarDescription.XML_SCHEMA) ;
XSGrammar grammar =
(XSGrammar)grammarPreparser.preparseGrammar(XMLGrammarDescri ption.XML_SCHEMA,is);
xsModel = grammar.toXSModel();
}
catch (Exception e)
{
//parser will return null pointer exception if the document is
structurally invalid
}
}
catch (Exception e)
{
}
Accessing the elements and types
--------------------------------
xsModel.getElementDeclaration(name, namespace)
xsModel.getTypeDefinition(name, namespace)
Lawrence
>Andrea Sichel wrote:
>> Hi, I'm using the wsdl4j lbrary and I'm parsing a wsdl file. If I want
>> to parse the "types" section and extract the complexType how I can do
>> it? Help me please!!
>>
>>
>Andrea,
>
>If one of our WSDL4J experts doesn't answer this, I suggest you post it
>to the Apache mailing list for WSDL4J since that's where the code is
>hosted. We pick it up and integrate in the WTP tools. You can probably
>find a code example for what you want to do by looking at the source for
>the wsdl2java code emmitter in Apache Axis 1.x.
>
>-- Arthur
|
|
|
|
Re: How I can parsing a complex Type? [message #117838 is a reply to message #116396] |
Fri, 08 July 2005 02:57  |
Eclipse User |
|
|
|
Kihup Boo wrote:
> Although the API is not finalized at the moment (in 0.7), it might be
> worth to look at the WSDL model as well (org.eclipse.wst.wsdl). The core
> model implements WSDL4J, and is integrated with the XML Schema Infoset
> Model (org.eclipse.xsd) seamlessly. Let me know if you need more info.
Just to elaborate a bit on what Kihup said. Our EMF based WSDL model
(org.eclipse.wst.wsdl) is an alternative implementation of the wsdl4j
model that provides very convenient access EMF based XML Schema model.
From a message's part you can call part.getElement() or
part.getTypeDefinition() and you will be returned an XSDElement or
XSDTypeDefinition. You can also obtain the inline schemas like by calling
definition.getTypes().getSchemas() and you'll get back a list of XMLSchema
model objects.
|
|
|
Powered by
FUDForum. Page generated in 0.03738 seconds