aspose file tools*
The moose likes Web Services and the fly likes Error parsing xml (apache cxf soap response) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Error parsing xml (apache cxf soap response)" Watch "Error parsing xml (apache cxf soap response)" New topic
Author

Error parsing xml (apache cxf soap response)

Nirmal Mukundan
Ranch Hand

Joined: Feb 21, 2007
Posts: 37

Hi,

I am trying to parse an xml



I am using the following code to parse the xml,



But I am continously getting the error

  • [Fatal Error] :1:1: Content is not allowed in prolog.
    org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.
    at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
    at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
    at com.test.xml.DOMExampleJava.main(DOMExampleJava.java:29)


  • I did a lot of search in the net and was not able to find the right solution. Kindly help me with the same.

    Regards
    Nirmal
    Carles Gasques
    Ranch Hand

    Joined: Apr 19, 2013
    Posts: 199
        
        1
    Hi,

    Try using this as the first line of the document


    Cheers,

    Amir Keibi
    Ranch Hand

    Joined: Apr 23, 2012
    Posts: 49

    Out of curiosity, why are you trying to manually parse a SOAP message?
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41823
        
      62
    Indeed, assuming that a WSDL for the WS exists (and it should, Apache CXF can do that), you should use the tools of your SOAP stack to generate Java client source code that handles the WS access and the SOAP for you.


    Ping & DNS - my free Android networking tools app
    Nirmal Mukundan
    Ranch Hand

    Joined: Feb 21, 2007
    Posts: 37

    Hi,

    I am parsing the soap response to get the occurance of a particular node and then get the values of the node.
    I thought I need to parse it as XML.

    Please advice a better way.

    I have generated the client classes from wsdl. But I wanted to parsse the response for getting the values of a a particular node.

    Regards
    Nirmal
    Tiklu Mukherjee
    Greenhorn

    Joined: Mar 14, 2013
    Posts: 7
    Nirmal Mukundan wrote:Hi,

    I am parsing the soap response to get the occurance of a particular node and then get the values of the node.
    I thought I need to parse it as XML.

    Please advice a better way.

    I have generated the client classes from wsdl. But I wanted to parsse the response for getting the values of a a particular node.

    Regards
    Nirmal


    Hi,

    Here i dont see you defining or identifying the Root Node for your SOAP when parsing.
    please go through the DocumentBuilderFactory class documentation.
    if you are still not able to parse the SOAP ,please let us know.

    Thanks,
    abhijitmukherjee655@gmail.com
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 41823
        
      62
    The generated Java code should provide access to all parts of the SOAP message, possibly via intermediate classes (which would also have been created).
    Amir Keibi
    Ranch Hand

    Joined: Apr 23, 2012
    Posts: 49

    Nirmal Mukundan wrote:
    I am parsing the soap response to get the occurance of a particular node and then get the values of the node.
    I thought I need to parse it as XML.

    Please advice a better way.


    The service engine (or your SOAP client) is already doing that. Simply put, if what you're after is in message body, then the engine (or client) automatically maps inputs and output of service functions to them. If it's in header, engine (or client) can "intercept" the message to read from/write to header.
    So unless you are creating something like a SOAP debugging (troubleshooting) tool, parsing messages is unnecessary.
    William Brogden
    Author and all-around good cowpoke
    Rancher

    Joined: Mar 22, 2000
    Posts: 12781
        
        5
    Getting back to the actual error:



    You get that when the first character of the document stream is NOT "<" - so you need to examine that response. SOAPui or TCPMON will let you do that.

    You may be surprised to see that your request never got to the SOAP service at all and you are getting an error message.

    Bill
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Error parsing xml (apache cxf soap response)