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>


Reply via email to