XML Schema Validation: SOAP Issue / Namespace Issue

bejhan
bejhan used Ask the Experts™
on
I am trying to get XML validation working for a SOAP server but I've run into a couple of issues.

XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://p2p.thalesgroup.com/wsdl/status/xsd"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  elementFormDefault="qualified"
  attributeFormDefault="qualified"
  targetNamespace="http://p2p.thalesgroup.com/wsdl/status/xsd">
 
  <xsd:element name="Alive">
    <xsd:complexType>
      <xsd:annotation>
        <xsd:documentation>
          - Alive is sent periodically to verify the connection status
        </xsd:documentation>
      </xsd:annotation>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

Open in new window


XML:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap-enc="http://www.w3.org/2003/05/soap-encoding" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soap:Body><Alive/></soap:Body>
</soap:Envelope>

Open in new window


First Issue:
SOAP elements are not being recognized.
Validator Output: Cannot Find The Declaration Of Element 'soap:Envelope'., Line '1', Column '225'.
I found a Stack Overflow thread describing the same issue but the described solutions do not work for me.

Second Issue:
Even if I remove the SOAP elements, I still have a namespace issue.
Validator Output: Cannot Find The Declaration Of Element 'Event'., Line '1', Column '8'.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
mccarlIT Business Systems Analyst / Software Developer
Top Expert 2015

Commented:
I am trying to get XML validation working

What are you trying to validate it with? What is actually performing the validation?

The problem is that it doesn't seem to be locating your XSD at all.

Author

Commented:
I'm passing the full XSD to a validator. I've tried QXMLSchemaValidator programatically and also an online tool manually, to the same result.

Author

Commented:
I changed my examples to simplify the question but the same problems remain.

I solved the second issue by removing a non-existent namespace URL from the XSD file:
targetNamespace="http://p2p.thalesgroup.com/wsdl/status/xsd"

Open in new window


Still grappling with the first issue.
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Author

Commented:
I solved the first issue by importing not just the namespace but also the schema:
<xsd:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/>

Open in new window

Commented:
Just to clarify, for anyone reading this in the future, the problem with the targetNamespace was not that it didn't exist.
After some more research, I realized that namespace URLs aren't actually resolved. Rather, they just serve as unique identifiers.
Why URLs were chosen is beyond me. This just added to my initial confusion.

The problem was actually that my XML file did not declare the namespace indicated by targetNamespace so the XML file and XSD file were not in agreement.
Removing the targetNamespace fixed the issue because doing so put the XSD in the global namespace, with which the XML file was dealing (since it didn't specify a namespace).

This could've instead been solved by setting the same namespace in the XML file.
<Alive xmlns="http://p2p.thalesgroup.com/wsdl/status/xsd"/>

Open in new window

Commented:
Another clarification, for anyone reading this in the future, importing the SOAP namespace and schema does not have the exact desired effect because the SOAP schema specifies lax validation for its body contents.

This means that:
- DESIRED: If a tag declared in my schema exists, it will be validated according to our a schema.
- UNDESIRED: If a tag not declared in my schema exists, it will pass validation.
- UNDESIRED: If the body is empty, it will pass validation.

My solution was download the SOAP schema and modify it to have strict validation for its body contents

Author

Commented:
I solved my own question.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial