views:

851

answers:

4

I can't get any SOAP messages to validate as valid XML. For example, the SOAP message below I took off of Wikipedia and it failed the Validome validator (http://www.validome.org/xml/validate/). Is the validator wrong or is there a mistake in the SOAP file? If the validator is wrong can you suggest another? It should take schemas into account. For example, W3C says that http://www.usaspending.gov/fpds/fpds.php?datype=X&company_name=Boeing&fiscal_year=2009&detail=1 is well-formed, but it actually is horrible invalid as Validome correctly points out.

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"&gt;
  <soapenv:Header>
    <wsa:ReplyTo>
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:Address&gt;
    </wsa:ReplyTo>
    <wsa:From>
      <wsa:Address>http://localhost:8080/axis2/services/MyService&lt;/wsa:Address&gt;
    </wsa:From>
    <wsa:MessageID>ECE5B3F187F29D28BC11433905662036</wsa:MessageID>
  </soapenv:Header>
  <soapenv:Body>
    <req:echo xmlns:req="http://localhost:8080/axis2/services/MyService/"&gt;
      <req:category>classifieds</req:category>
    </req:echo>
  </soapenv:Body>
</soapenv:Envelope>
A: 

I've looked through the output from the validator and it's working fine, the SOAP message you're using is as fault. Certainly the errors it's reporting are there. Also there are more errors that the validator isn't reporting I suspect once if finds one problem with the SOAP message it unwinds to the next parent element and carries on.

For instance the next element after <mod_eeduns/> should be <total_obligatedAmount/> which (i assume) has been superseded by <total_obligatedAmount_within_this_search/>

If you have to work with this SOAP I suggest you create your own XSD, various tools exist to generate them from an existing Xml message. Also contacting the site and passing on the problems you've found (using subtlety) would be useful to them. If you don't have to use this service then so much the better.

When you say that W3C says it's well formed, I'm not sure what you mean. For instance the inclusion of a space in the element name ..<eeParentDuns ></eeParentDuns>.. and the fact they don't match is not valid in any form of Xml, let alone SOAP+XSD.

MrTelly
Your answer is talking about an XML file I linked to as an example of an invalid file and completely ignoring the SOAP example I posted.
Ben McCann
Guilty as charged, thanks to John for editting in the SOAP, and over to the rest of SO for a solution
MrTelly
A: 

The XML you posted might be perfectly valid - if you had specified the location of the schemas with which to validate it.

"Valid" in XML terms means "valid according to a set of XML Schemas". In the absence of any schemas, the concept of validity makes no sense.

John Saunders
Doesn't the xmlns in the example specify the schemas?
Ben McCann
No. That defines prefixes for the namespaces.
John Saunders
So how would you correct the message to specify the schema location? Would it be something like:<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" soapenv:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
Ben McCann
No. Among other things, schema locations are hints only. A consumer of the XML is not required to use them. Second, your syntax is wrong, it's `xsi:schemaLocation="namespace schemaUrl namespace schemaUrl"` or `xsi:noNamespaceSchemaLocation="schemaUrl schemaUrl"`.
John Saunders
A: 

The following SOAP message validates:

<soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing"&gt;
  <soapenv:Header>
    <wsa:ReplyTo>
      <wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous&lt;/wsa:Address&gt;
    </wsa:ReplyTo>
    <wsa:From>
      <wsa:Address>http://localhost:8080/axis2/services/MyService&lt;/wsa:Address&gt;
    </wsa:From>
    <wsa:MessageID>ECE5B3F187F29D28BC11433905662036</wsa:MessageID>
  </soapenv:Header>
  <soapenv:Body>
    <req:echo xmlns:req="http://localhost:8080/axis2/services/MyService/"&gt;
      <req:category>classifieds</req:category>
    </req:echo>
  </soapenv:Body>
</soapenv:Envelope>
Ben McCann
Ben, please learn to use the little "0101" toolbar button (or Control-K) to format code and XML.
John Saunders
Also, this only validates partially, because the SOAP Envelope schema permits random XML in the header. Change "ReplyTo" to "ReplyFrom" in both start and end tags and watch what happens.
John Saunders
A: 

To make sure a SOAP message looks exactly how it should, you should validate it against all the schemas that are referenced in that message. In your example, that's SOAP, WS-Addressing, and schema for the custom namespace (myService).

The schemas for SOAP and WS-Addressing are available from the URL that's also used for the namespace, but that's just convention, not a requirement.

sapporo