How to solve SAXException: Invalid element in

后端 未结 3 637
感情败类
感情败类 2020-12-21 09:03

I try to get results from a webservice in the following way.

List result = new Vector();
LibrarySearchRequest request = new LibrarySearchRequest(queryString)         


        
相关标签:
3条回答
  • 2020-12-21 09:34

    I had the same problem and after trying the Web Service using SoapUI, I discovered two inconsistencies between the fields I was getting in the response and the fields generated by the WSDL:

    1- For some reason, when I generated my structure from the WSDL, it put a space after the field name, like this:

    elemField.setXmlName(new javax.xml.namespace.QName("http://namespaceuri.here", "book "));
    

    I just removed that space and it fixed the problem.

    2- In the response I was getting an additional field that was not present in my class. What I did here was to add the field to my class, and to add also in the static block, just like any other field.

    Hope it helps.

    0 讨论(0)
  • 2020-12-21 09:39

    Workaround for this problem:

    Open your generated class(For this question it is librarysearch.soft.Book). See the static code block which defines the properties(name, type, etc.) of fields.

    You'll something like below:

    elemField.setXmlName(new javax.xml.namespace.QName("", "book"));
    

    change it by adding namespaceURI to it (use same namespameURI which is used at setXmlType call):

    elemField.setXmlName(new javax.xml.namespace.QName("http://your.namespaceuri.here", "book"));
    
    0 讨论(0)
  • 2020-12-21 09:40

    This could be related to this bug (AXIS-2758), unresolved with Axis 1.x.

    This problem can appear if your client stub is not up to date with the server side (the WSDL file). You could have to re-generate it. Like with axistools:wsdl2java.

    The best nowadays, provided you use at least Java 6, is maybe to use JAX-WS on the client side (JAX-WS Maven Plugin). But it could not work with old SOAP Services using RPC/Encoded... Prefer the Document/Literal style.

    0 讨论(0)
提交回复
热议问题