Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validating a SOAP document using XSD

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic