• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error parsing xml (apache cxf soap response)

 
Ranch Hand
Posts: 37
Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
     
    Ranch Hand
    Posts: 199
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi,

    Try using this as the first line of the document


    Cheers,

     
    Ranch Hand
    Posts: 49
    Eclipse IDE Java Linux
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Out of curiosity, why are you trying to manually parse a SOAP message?
     
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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.
     
    Nirmal Mukundan
    Ranch Hand
    Posts: 37
    Eclipse IDE Oracle
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    Greenhorn
    Posts: 7
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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
    Rancher
    Posts: 43081
    77
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
    Posts: 49
    Eclipse IDE Java Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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.
     
    Author and all-around good cowpoke
    Posts: 13078
    6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    reply
      Bookmark Topic Watch Topic
    • New Topic