Note that there are some explanatory texts on larger screens.

plurals
  1. POXML Schema: Namespace issues when importing shared elements
    text
    copied!<p>When trying to import shared definitions from a XML Schema, I can properly reference shared types, but referencing shared elements causes validation errors.</p> <p>This is the schema that imports the shared definitions (example.xsd):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:shared="http://shared.com"&gt; &lt;xs:import namespace="http://shared.com" schemaLocation="shared.xsd"/&gt; &lt;xs:element name="example"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="importedElement"/&gt; &lt;xs:element ref="importedType"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="importedElement"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="shared:fooElement"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="importedType"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="bar" type="shared:barType"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;/xs:schema&gt; </code></pre> <p>These are the shared definitions (shared.xsd):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://shared.com" targetNamespace="http://shared.com"&gt; &lt;xs:element name="fooElement"&gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:integer"/&gt; &lt;/xs:simpleType&gt; &lt;/xs:element&gt; &lt;xs:simpleType name="barType"&gt; &lt;xs:restriction base="xs:integer"/&gt; &lt;/xs:simpleType&gt; &lt;/xs:schema&gt; </code></pre> <p>Now consider this XML instance:</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;example xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="example.xsd"&gt; &lt;importedElement&gt; &lt;fooElement&gt;42&lt;/fooElement&gt; &lt;/importedElement&gt; &lt;importedType&gt; &lt;bar&gt;42&lt;/bar&gt; &lt;/importedType&gt; &lt;/example&gt; </code></pre> <p>When validated, the "importedType" works perfectly fine, but the "importedElement" gives the following error:</p> <blockquote> <p>Invalid content was found starting with element 'fooElement'. One of '{"<a href="http://shared.com" rel="nofollow noreferrer">http://shared.com</a>":fooElement}' is expected</p> </blockquote> <p>I would guess that my troubles are related to namespace issues (hence the somehow misleading "got fooElement but was expecting fooElement") -- any hints on what's wrong here?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload