Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Schema: error with restriction in simpleContent

From: Pavel Lepin <p.lepin@-------.--->
To: NULL
Date: 11/1/2007 1:26:00 PM


Please quote what you're replying to.

Kai Schlamp <stroncococcus@g...> wrote in
<1193913218.460782.168360@o...>:
> I just want to scheme a simple xml tag like this
> <mytag myattr="10">foo</mytag>
> and want to restrict "foo" to the length of 10 characters,
> thats all. But I didn't find an example on the web for
> doing such an restriction in this case (I am pretty new to
> XML, but I think you already know that ;-))
> As I understand the mytag must be a complex type, cause it
> has an attribute ("myattr") and a content ("foo").
> What's the best way to achieve this?

Well, restrict then extend.

pavel@debian:~/dev/schema$ a schema.xsd
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="textarea" type="textareaType"/>
  <xs:attribute name="label" type="xs:string"/>
  <xs:complexType name="textareaType">
    <xs:simpleContent>
      <xs:extension base="str-10-chr">
        <xs:attribute ref="label" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
  <xs:simpleType name="str-10-chr">
    <xs:restriction base="xs:string">
      <xs:maxLength value="10"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>
pavel@debian:~/dev/schema$ for F in sch*.xml ; do
xmllint --schema schema.xsd $F ; echo ; done
<?xml version="1.0"?>
<textarea>more than 10 characters</textarea>
sch1.xml:1: element textarea: Schemas validity error :
Element 'textarea': The attribute 'label' is required but
missing.
sch1.xml:1: element textarea: Schemas validity error :
Element 'textarea': [facet 'maxLength'] The value has a
length of '23'; this exceeds the allowed maximum length
of '10'.
sch1.xml:1: element textarea: Schemas validity error :
Element 'textarea': 'more than 10 characters' is not a
valid value of the atomic type 'str-10-chr'.
sch1.xml fails to validate

<?xml version="1.0"?>
<textarea label="aaa">more than 10 characters</textarea>
sch2.xml:1: element textarea: Schemas validity error :
Element 'textarea': [facet 'maxLength'] The value has a
length of '23'; this exceeds the allowed maximum length
of '10'.
sch2.xml:1: element textarea: Schemas validity error :
Element 'textarea': 'more than 10 characters' is not a
valid value of the atomic type 'str-10-chr'.
sch2.xml fails to validate

<?xml version="1.0"?>
<textarea>&lt;10 chars</textarea>
sch3.xml:1: element textarea: Schemas validity error :
Element 'textarea': The attribute 'label' is required but
missing.
sch3.xml fails to validate

<?xml version="1.0"?>
<textarea label="aaa">&lt;10 chars</textarea>
sch4.xml validates

pavel@debian:~/dev/schema$

I heartily recommend reading W3C's XML Schema Primer. It
might take you a day or two, but will give you a solid
understanding of the basics.

-- 
"I can't help but wonder if you... don't know a hell of a
lot more about practically every subject than Solomon ever
did."


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent