Note that there are some explanatory texts on larger screens.

plurals
  1. POXML Schema: using attribute definition in complexType
    text
    copied!<p>I have some problems with XML validation using SAX parser. Here is a simple XML Schema I made to present the problem:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0"?&gt; &lt;xs:schema targetNamespace="urn:test" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns="urn:test"&gt; &lt;xs:element name="root"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element name="content" type="ContentType" maxOccurs="unbounded" /&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:complexType name="ContentType"&gt; &lt;xs:simpleContent&gt; &lt;xs:extension base="xs:string"&gt; &lt;xs:attribute ref="title" use="required" /&gt; &lt;/xs:extension&gt; &lt;/xs:simpleContent&gt; &lt;/xs:complexType&gt; &lt;xs:attribute name="title" type="xs:string" /&gt; &lt;/xs:schema&gt; </code></pre> <p>And here is a pretty simple XML file which in my opinion should be valid with regards to my schema:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt; &lt;root xmlns="urn:test"&gt; &lt;content title="Title"&gt; Content comes here... &lt;/content&gt; &lt;/root&gt; </code></pre> <p>The interesting thing is that when I try to parse this XML file, I receive the following validation error:</p> <pre>cvc-complex-type.3.2.2: Attribute 'title' is not allowed to appear in element 'content'.</pre> <p>But if I remove the <em>title</em> attribute of the <em>content</em> element from the XML file, I still receive validation errors:</p> <pre>cvc-complex-type.4: Attribute 'title' must appear on element 'content'.</pre> <p>I have no idea what the problem is. Of course, this is just a simple example presenting the problem. I would like to understand the cause of this behavior. Also, it would be nice to find a resolution. I am not sure whether my Java code doing the validation is important in this case, I will post it later if it is necessary.</p> <p>Any help would be highly appreciated.</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