EDIT 13/07/2020 :
What I'm trying to achieve is validate the 3 elements in the XML.
The DocumentId element will always contain a string, the ID element will always contain a string, and the element01 will always contain a string and have the attribute xsi:type="ns11:creditNote"
.
The element Document and DocumentList can have any attributes from any namespaces.
The 3 elements to validate are :
/po:DocumentList/po:Document/po:DocumentId
/po:DocumentList/po:Document/po:ID
/po:DocumentList/po:Document/po:element01
with the attributexsi:type="ns11:creditNote"
This is the XML :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<po:DocumentList xmlns:po="http://www.example.com/PO1"
xmlns:ns11="urn:oasis:names:specification:ubl:schema:xsd:Invoice-1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.com/PO1 Main.xsd" indexing="false" numPages="2" pageId="0" itemsPerPage="2" itemCount="3">
<po:Document>
<po:DocumentId>b6f066ea-1d48-566c-967a-f81a2d935d59</po:DocumentId>
<po:ID>documents/b6f066ea-1d48-566c-967a-f81a2d935d59</po:ID>
<po:element01 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns11:creditNote">documents/b6f066ea-1d48-566c-967a-f81a2d935d59</po:element01>
</po:Document>
</po:DocumentList>
I created a main XSD file (Main.xsd
) for the namespace http://www.example.com/PO1
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="XMLSchema-versioning" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:po="http://www.example.com/PO1" xmlns:ns11="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" targetNamespace="http://www.example.com/PO1" elementFormDefault="qualified" attributeFormDefault="unqualified" vc:minVersion="1.1">
<xs:import namespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" schemaLocation="Main_Sub_1.xsd"/>
<xs:element name="DocumentList">
<xs:complexType>
<xs:sequence>
<xs:element name="Document">
<xs:complexType>
<xs:sequence>
<xs:element name="DocumentId" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="ID" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="element01" type="ns11:creditNote"/>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:schema>
And I created another file Main_Sub_1.xsd
for the namespace urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" attributeFormDefault="qualified" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns11="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2">
<xs:simpleType name="creditNote">
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:schema>
However when I try to validate the main XSD file I get this error :
"'ns11:creditNote' must refer to an existing simple or complex type."
I made some experiments, and tried changing the namespace urn:oasis:names:specification:ubl:schema:xsd:Invoice-2
to "test01" and it works, but as soon as I use this specific urn, it throws an error.
I saw that the urn points to an xsd schema that can be viewed here : https://schemas.liquid-technologies.com/oasis/ubl/2.0/?page=ubl-invoice-2_0_xsd.html
So I'm guessing the validator, when seeing this namespace, instead of importing my file with the type creditNote I created, looks at a file in a distant server which does not have the type creditNote defined. I don't have a lot of experience with XML and XSD but since replacing the urn with anything else makes my validation work, that's how I understood it.
How can I fix this error ?
xsi:type="ns11:creditNote"
from the XML or 2. Define the typens11:creditNote
somewhere. – zx485