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:
- If element is prefixed, namespace for the prefix must be defined.
- 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>