This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validating a SOAP document using XSD

 
John Fairbairn
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic