简体   繁体   中英

SAXParseException: Element type SOAP:Text must be followed by either attribute specifications, “>” or “/>”

I'm attempting to read a response from a web service call in a junit test running in Eclipse Galileo. I'm able to successfully receive responses except when the response is a SOAP fault. Then I get the following exception: org.xml.sax.SAXParseException: Element type "SOAP:Text" must be followed by either attribute specifications, ">" or "/>"

I have validated the XML in LiquidXML Studio against the SOAP 1.2 schema and it checks out.

Here is the XML response that SAX appears to be choking on. It has been stripped to the minimum in an attempt to eliminate anything obvious (I even made sure it didn't have any self closing elements):

<SOAP:Envelope xmlns:SOAP="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP_ENC="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP:Header> </SOAP:Header> <SOAP:Body> <SOAP:Fault> <SOAP:Code> <SOAP:Value>SOAP:Sender</SOAP:Value> <SOAP:Subcode> <SOAP:Value>SOAP:Sender</SOAP:Value> </SOAP:Subcode> </SOAP:Code> <SOAP:Reason> <SOAP:Text xml:lang=""> </SOAP:Text> </SOAP:Reason> <SOAP:Node> </SOAP:Node> <SOAP:Role> </SOAP:Role> <SOAP:Detail> </SOAP:Detail> </SOAP:Fault> </SOAP:Body> </SOAP:Envelope>

Any help would be appreciated.

Its obviously not regcognising 'xml:lang=""' as an attribute. CHeck with your xsd or xmlSchema what attributes are valid. Also you should be using

xml:lang=&quot;&quot;

rather than "" although most parsers forgive you for this.

我认为问题在于将soap Fault xml映射到其相应的对象。

It turns out the problem was related to a tool I was using to return static string responses to web service requests. The static response XML contained the xml:lang attribute. However, when the tool was returning the static string, it was modifying it on the way out and replacing xml:lang on-the-fly with the fully qualified namespace equivalent {http://www.w3.org/XML/1998/namespace}lang. When this response was received, the SAXParser was choking because it couldn't interpret the fully qualified equivalent.

The tool returning the static responses used a Groovy xml parser as an integral part of sending the response. The XmlParser Groovy class has a constructor that I had to change to set validating and namespaceAware attributes to false. So instead of XmlParser(), the tool now calls XmlParser(false, false). Problem solved. Thanks for the responses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM