Forum Moderators: open
This is my current complexType for it:
<xs:complexType name="wordType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="syllables" type="ns1:lowint" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
This schema is adequately diligent with the attribute (using a customized "lowint" type which only allows integers from 1 to 7), but I want constraints on the contents of the element as well. For one thing, it may not be empty, and must match a "[\w]+" pattern (alphanumeric, no punctuation or whitespace)
the finished schema should not validate the following invalid XML fragments:
<word syllables="2"></word>
<word syllables="2">1 .23</word>
<word syllables="2">two words</word>
I'm pretty new to schema... I'm fumbling with it. I've tried dozens of combinations to get this to validate
<elem val="123">notempty</elem>
<elem val="1">a</elem>
<elem val="2">b</elem>
<elem val="3">c</elem>
<!-- all of the following should fail -->
<elem val="notnumeric">notempty</elem>
<elem val="123">two words</elem>
<elem val="123"> s p a c e </elem>
<elem val="123">Wow!</elem>
<elem val="123">some<b>bold</b>stuff</elem>
<elem val="123"></elem>
<elem>notempty</elem>
<elem badattr="noway"></elem>
<elem badattr=""></elem>
<elem><eek/></elem>
<elem><eek>definitely not</eek></elem>
<elem/>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="wrapper">
<xs:complexType>
<xs:sequence>
<xs:element name="elem">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="val" type="xs:integer" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
and so badly documented?
Welcome to the world of XML, where Google returns 30,000 hits, almost every single one of which is the same article off of XML.com or W3Schools, paraphrased by people who barely understand it.
I figured out, REAL QUICK, that the best thing I could do was to chuck my reference book in the trash and get a copy of <oXygen/>.
Can't guarantee an ETA on the regex. I'm pretty swamped right now...
<word syllables="2">doughnut</word>
This one enforces having stuff in the Content
<xs:simpleType name="wordType">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z]+"/>
</xs:restriction>
</xs:simpleType>
This one enforces the existence and value of the attribute
<xs:complexType name="wordType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="syllables" type="ns1:lowint" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="lowint">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="7"/>
</xs:restriction>
</xs:simpleType>
now... how do I combine them... hmm
Try this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="smallInt">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="7"/>
</xs:restriction>
</xs:simpleType><xs:simpleType name="myString">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z]+"/>
</xs:restriction>
</xs:simpleType><xs:element name="wrapper">
<xs:complexType>
<xs:sequence>
<xs:element name="elem">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="myString">
<xs:attribute name="syllables" type="smallInt" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<xs:simpleType name="lowint">
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="7"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="isword">
<xs:restriction base="xs:string">
<xs:pattern value="[a-z A-Z']+"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="wordType" mixed="true">
<xs:simpleContent>
<xs:extension base="ns1:isword">
<xs:attribute name="syllables" type="ns1:lowint" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Give me a moment to compare yours and mine and see if they do the same thing.