Return-Path: Delivered-To: apmail-ws-axis-user-archive@www.apache.org Received: (qmail 67658 invoked from network); 19 Sep 2005 02:29:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 19 Sep 2005 02:29:46 -0000 Received: (qmail 46442 invoked by uid 500); 19 Sep 2005 02:29:36 -0000 Delivered-To: apmail-ws-axis-user-archive@ws.apache.org Received: (qmail 46428 invoked by uid 500); 19 Sep 2005 02:29:35 -0000 Mailing-List: contact axis-user-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: axis-user@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-user@ws.apache.org Received: (qmail 46413 invoked by uid 99); 19 Sep 2005 02:29:35 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 18 Sep 2005 19:29:35 -0700 X-ASF-Spam-Status: No, hits=0.1 required=10.0 tests=HTML_40_50,HTML_MESSAGE,HTML_TITLE_EMPTY X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy includes SPF record at spf.trusted-forwarder.org) Received: from [209.68.1.20] (HELO relay.pair.com) (209.68.1.20) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 18 Sep 2005 19:29:44 -0700 Received: (qmail 90468 invoked from network); 19 Sep 2005 02:29:32 -0000 Received: from unknown (HELO ?127.0.0.1?) (unknown) by unknown with SMTP; 19 Sep 2005 02:29:32 -0000 X-pair-Authenticated: 222.165.173.184 Message-ID: <432E2281.2050305@opensource.lk> Date: Mon, 19 Sep 2005 08:29:21 +0600 From: Eran Chinthaka Reply-To: chinthaka@opensource.lk User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: axis-user@ws.apache.org Subject: Re: [axis2] Parsing a WSDL file References: <43296E39.6070002@tiscalinet.it> <4329803A.8090001@opensource.lk> <4329BEB9.5060108@tiscalinet.it> <432A5650.9070804@opensource.lk> <000e01c5bb6c$7c466f20$291f72d5@deep> <432DB921.60200@uni-mb.si> In-Reply-To: <432DB921.60200@uni-mb.si> Content-Type: multipart/alternative; boundary="------------070307080403060101000903" X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N This is a multi-part message in MIME format. --------------070307080403060101000903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi Andrej, Our OM tree can contain two types of nodes, namely; OMText and OMElement. The OMElement will contain eii of the xml and OMText will contain character ii. Your WSDL (or whatever xml) is having both texts and elements under the document element. So casting children.next() to either OMText or OMElement will DEFINITELY give you a CCE. If you just want to print out an XML, use OMOutput. XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader( new FileReader("ServisFirstTry1.wsdl")); StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser); OMElement root = builder.getDocumentElement(); OMOutputImpl out = new OMOutputImpl(System.out, false); root.serialize(out); out.flush(); But I think you want to do more than just dumping a WSDL :-) Better read some of the tutorials on the web on AXIOM. - Chinthaka Andrej Taranenko wrote: > Hi, > I am trying to parse a WSDL file, so I could print out the contents by > its elements. The file is attached. > I am using the following code: > > XMLStreamReader parser = > XMLInputFactory.newInstance().createXMLStreamReader( > new > FileReader("ServisFirstTry1.wsdl")); > StAXOMBuilder builder = new > StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser); > OMElement root = builder.getDocumentElement(); > System.out.println("WSDL print "); > > System.out.println("--------------------------------------------------"); > int i = 0; > Iterator children = root.getChildren(); > while (children.hasNext()) { > System.out.print(i+": "); i++; > OMElement node = (OMElement) children.next(); // <--- > exception here! > System.out.println(node.getFirstElement().getText()); > } > > but I get the following exception: > Exception in thread "main" java.lang.ClassCastException: > org.apache.axis2.om.impl.llom.OMTextImpl > at izpisWSDL.main(izpisWSDL.java:57) > > if I use OMText instead of OMElement a different exception occurs. > Any help? > > Thanks in advance, > Andrej > >------------------------------------------------------------------------ > > > targetNamespace="http://services.axis2.apache.org/ServiceFirstTry" > xmlns="http://schemas.xmlsoap.org/wsdl/" > xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" > xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" > xmlns:tns="http://services.axis2.apache.org/ServiceFirstTry" > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > xmlns:xsd1="http://services.axis2.apache.org/xsd" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> > > xmlns="http://www.w3.org/2001/XMLSchema" > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" > elementFormDefault="qualified"> > > > > > > > > > > > > > > > > > type="tns:ServisFirstTryPortType"> > > > > > > > > > > > > > > > > > > --------------070307080403060101000903 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi Andrej,

Our OM tree can contain two types of nodes, namely; OMText and OMElement.

The OMElement will contain eii of the xml and OMText will contain character ii. Your WSDL (or whatever xml) is having both texts and elements under the document element. So casting children.next() to either OMText or OMElement will DEFINITELY give you a CCE.

If you just want to print out an XML, use OMOutput.

XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(
                                                         new FileReader("ServisFirstTry1.wsdl"));
StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser);
   OMElement root = builder.getDocumentElement();
OMOutputImpl out = new OMOutputImpl(System.out, false);
root.serialize(out);
out.flush();

But I think you want to do more than just dumping a WSDL :-)

Better read some of the tutorials on the web on AXIOM.



- Chinthaka


Andrej Taranenko wrote:
Hi,
I am trying to parse a WSDL file, so I could print out the contents by its elements. The file is attached.
I am using the following code:

   XMLStreamReader parser = XMLInputFactory.newInstance().createXMLStreamReader(
                                                         new FileReader("ServisFirstTry1.wsdl"));
   StAXOMBuilder builder = new StAXOMBuilder(OMAbstractFactory.getOMFactory(), parser);
   OMElement root = builder.getDocumentElement();
     System.out.println("WSDL print ");
   System.out.println("--------------------------------------------------");
   int i = 0;
   Iterator children = root.getChildren();
   while (children.hasNext()) {
       System.out.print(i+": "); i++;
       OMElement node = (OMElement) children.next();  // <--- exception here!
       System.out.println(node.getFirstElement().getText());
   }

but I get the following exception:
Exception in thread "main" java.lang.ClassCastException: org.apache.axis2.om.impl.llom.OMTextImpl
   at izpisWSDL.main(izpisWSDL.java:57)

if I use OMText instead of OMElement a different exception occurs.  Any help?

Thanks in advance,
Andrej

<?xml version="1.0" encoding="UTF-8"?> <definitions name="ServisFirstTry" targetNamespace="http://services.axis2.apache.org/ServiceFirstTry" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://services.axis2.apache.org/ServiceFirstTry" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsd1="http://services.axis2.apache.org/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <types> <schema targetNamespace="http://services.axis2.apache.org/xsd" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" elementFormDefault="qualified"> <element name="metoda4param" type="xsd:string"/> <element name="metoda4return" type="xsd:string"/> </schema> </types> <message name="metoda4"> <part element="xsd1:metoda4param" name="aVal"/> </message> <message name="metoda4Response"> <part element="xsd1:metoda4return" name="result"/> </message> <portType name="ServisFirstTryPortType"> <operation name="metoda4"> <input message="tns:metoda4" name="metoda4"/> <output message="tns:metoda4Response" name="metoda4Response"/> </operation> </portType> <binding name="ServisFirstTryPortBinding" type="tns:ServisFirstTryPortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="metoda4"> <soap:operation soapAction="metoda4" style="rpc"/> <input name="metoda4"> <soap:body namespace="http://services.axis2.apache.org/ServiceFirstTry" use="literal"/> </input> <output name="metoda4Response"> <soap:body namespace="http://services.axis2.apache.org/ServiceFirstTry" use="literal"/> </output> </operation> </binding> <service name="ServisFirstTry"> <port binding="tns:ServisFirstTryPortBinding" name="ServisFirstTryPort"> <soap:address location="http://localhost/axis2/services/ServisFirstTry.wsdl"/> </port> </service> </definitions>
--------------070307080403060101000903--