XML Schema Validation: SOAP Issue / Namespace Issue

I am trying to get XML validation working for a SOAP server but I've run into a couple of issues.

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://p2p.thalesgroup.com/wsdl/status/xsd"
  <xsd:element name="Alive">
          - Alive is sent periodically to verify the connection status

Open in new window

<?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">

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'.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
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.
bejhanAuthor 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.
bejhanAuthor 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:

Open in new window

Still grappling with the first issue.
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

bejhanAuthor 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

bejhanAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bejhanAuthor 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
bejhanAuthor Commented:
I solved my own question.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.