aspose file tools*
The moose likes XML and Related Technologies and the fly likes Validating a SOAP document using XSD Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Validating a SOAP document using XSD" Watch "Validating a SOAP document using XSD" New topic
Author

Validating a SOAP document using XSD

John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55
Hey all,
New to SOAP...
What I'd like to do is validate that the XML in the soap header has all the elements I need in the correct sequence. I'd also like to validate that the xml within the soap body has all the elements I need in the correct sequence.
My SOAP document looks like:

Should I create an XSD for just the XML within the SOAP body? Is it possible to create an XSD to validate that the <SOAP:Header> contains all the required elements in the correct sequence?
John
Christophe Grosjean
Ranch Hand

Joined: Jan 22, 2002
Posts: 51
I'm not sure to understand clearly your needs.
If you want to validate only your SOAP header, you can define an XSD for the whole document, specifying that <soap:envelope> is an element containing a <soap:header> (which you fully specify in the xsd) and any other element (corresponding to your body) with <xsd:any/> in your schema
John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55
Hi Christophe,
I want to validate the entire SOAP document. I'll explain my problem more clearly.
I created the following SOAP document:

I used XML Spy to generate a schema for me given this xml. The generated schema looked like:

When I try saving the schema, I get an error:
SOAP:BodyType cannot have a namespace prefix. Please remove prefix or use ref=instead!

How do I reference the SOAP namespace in my XSD? Can you reference a namespace in the name attribute of an element?
Thanks for your help.
John
John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55
Hi Christophe,
I want to validate the entire SOAP document. I'll explain my problem more clearly.
I created the following SOAP document:

I used XML Spy to generate a schema for me given this xml. The generated schema looked like:

When I try saving the schema, I get an error:
SOAP:BodyType cannot have a namespace prefix. Please remove prefix or use ref=instead!

How do I reference the SOAP namespace in my XSD? Can you reference a namespace in the name attribute of an element?
Thanks for your help.
John
Christophe Grosjean
Ranch Hand

Joined: Jan 22, 2002
Posts: 51
simply add :
xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/
to the tag
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
of your xsd file.
Christophe
John Fairbairn
Ranch Hand

Joined: May 30, 2002
Posts: 55
Hi Christophe,
Thanks for your reply. I tried adding the new namespace so my xsd now looks like:

When saving, I still get the error:
SOAP:BodyType cannot have a namespace prefix. Please remove prefix or use ref=instead!

Not sure why it does not recognize the namespace.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validating a SOAP document using XSD