2

I have the following XML:

<ns1:verifySignedDocumentResponse xmlns:ns1="http://signing.ws.comarch.gov">
    <verifySignedDocumentReturn xmlns:ns2="http://exception.ws.comarch.gov">Some string content...</verifySignedDocumentReturn>
</ns1:verifySignedDocumentResponse>

In verifySignedDocumentReturn case I'm wondering, is it correct to define the prefix (xmlns:ns2=...), but not to qualify (ns2:verifySignedDocumentReturn) the appropriate element with this prefix?

w3schools.com gives examples, which show:

  1. If element is prefixed, namespace for the prefix must be defined.
  2. Element should't be prefixed, if default namespace is used.

But in my example there is no default namespace. So, I expect verifySignedDocumentReturn to be prefixed with ns2.

I've got this XML-snippet from real service, so I wonder: is it correct and valid? Or just service creators' carelessness? I ask, because I'm new to XML/XSD.

I've tried to generate XSD from this XML with different online-generators, but no generated schema looks reasonable.

Variant 1 (does not take into account ns2 namespace at all):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           elementFormDefault="qualified" 
           targetNamespace="http://signing.ws.comarch.gov" 
           xmlns:ns1="http://signing.ws.comarch.gov">
   <xs:element name="verifySignedDocumentResponse">
   <xs:complexType>
      <xs:sequence>
        <xs:element name="verifySignedDocumentReturn" form="unqualified" 
                    type="xs:string"/>
      </xs:sequence>
   </xs:complexType>
 </xs:element>

Variant 2:

schema0.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:ns1="http://signing.ws.comarch.gov" 
           xmlns:ns2="http://exception.ws.comarch.gov" 
           attributeFormDefault="unqualified" 
           elementFormDefault="qualified" 
           targetNamespace="http://signing.ws.comarch.gov" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:import schemaLocation="schema1.xsd" />
  <xs:element name="verifySignedDocumentResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="verifySignedDocumentReturn" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

schema1.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <xs:element name="verifySignedDocumentReturn" type="xs:string" />
</xs:schema>

1 Answer 1

1

The first thing to note is the declaration of xmlns:ns2="http://exception.ws.comarch.gov" in your XML document does nothing. Its just defining an alias ns2, which is never used.

Both the generated schemas look OK. A few notes about them though.

Although the first schema fits neatly in a single XSD, typically the elementFormDefault is set to qualified and not changed within the schema. In this schema the form is being set to unqualified for the inner element. I'm not 100% sure, but I think that a validating XML parser using this schema will treat verifySignedDocumentReturn as if its in the namespace "http://signing.ws.comarch.gov". I think changing the form in the middle of a XSD document is asking for incompatibility issues.

The second set of schemas look OK.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for reply! Although these generated schemata look fine, none of them fully comply with the final XML-document. Also I understand, that xmlns:ns2="... does nothing. It was SOAP-server response, which should be just parsed, not sent anywhere. So, what is your resolution? Can I consider that XML-snippet as bad practice example or it is useful for something? And, if useful, for what?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.