Reputation: 109
I have the following xml:
<?xml version="1.0"?>
<BookStore xmlns="http://www.books.org"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://www.books.org
BookStore.xsd">
<Book category="Life style">
<Status>Available</Status>
<Title lang="en">Hour before dawn</Title>
<Author>
<Name>Paul McCartney</Name>
<Genre>M</Genre>
</Author>
<Date>
<Day>23</Day>
<Month>03</Month>
<Year>1999</Year>
</Date>
<Price type="euro">29.99</Price>
<ISBN>1-56592-245-2</ISBN>
<Publisher>McMilli Publishing</Publisher>
</Book>
<Book category="Philosophy">
<Status>Not available</Status>
<Title lang="de">Thus spoke Zarathustra</Title>
<Author>
<Name>Friedrich Nietzsche</Name>
<Genre>M</Genre>
</Author>
<Date>
<Day>21</Day>
<Month>11</Month>
<Year>1877</Year>
</Date>
<Price type="euro">39.15</Price>
<ISBN>0-440-34319-4</ISBN>
<Publisher>Sell Publishing Co.</Publisher>
</Book>
<Book category="Fiction">
<Status>Available</Status>
<Title lang="en">To kill a mockingbird</Title>
<Author>
<Name>Harper Lee</Name>
<Genre>M</Genre>
</Author>
<Date>
<Day>15</Day>
<Month>03</Month>
<Year>1982</Year>
</Date>
<Price type="euro">35.15</Price>
<ISBN>0-454-25215-8</ISBN>
<Publisher>Harper Row</Publisher>
</Book>
<Book category="Fantasy">
<Status>Available</Status>
<Title lang="en">Hexed</Title>
<Author>
<Name>Ilona Andrews</Name>
<Genre>F</Genre>
</Author>
<Author>
<Name>Yasmine Galenorn</Name>
<Genre>F</Genre>
</Author>
<Author>
<Name>Allyson James</Name>
<Genre>F</Genre>
</Author>
<Author>
<Name>Jeanne Stein</Name>
<Genre>F</Genre>
</Author>
<Date>
<Day>01</Day>
<Month>01</Month>
<Year>2011</Year>
</Date>
<Price type="euro">19.8</Price>
<ISBN>3-521-77423-9</ISBN>
<Publisher>Harper & Row</Publisher>
</Book>
<Book category="Web">
<Status>Not available</Status>
<Title lang="en">SCJP Sun certified programmer for Java 6</Title>
<Author>
<Name>Kathy Sierra</Name>
<Genre>F</Genre>
</Author>
<Author>
<Name>Bert Bates</Name>
<Genre>M</Genre>
</Author>
<Date>
<Day>06</Day>
<Month>09</Month>
<Year>2011</Year>
</Date>
<Price type="euro">55</Price>
<ISBN>2-421-52214-1</ISBN>
<Publisher>Learnkey</Publisher>
</Book>
<Book category="Horror">
<Status>Available</Status>
<Title lang="en">Out of the depths</Title>
<Author>
<Name>Cathy MacPhail</Name>
<Genre>F</Genre>
</Author>
<Date>
<Day>08</Day>
<Month>12</Month>
<Year>2013</Year>
</Date>
<Price type="euro">41</Price>
<ISBN>7-666-21242-7</ISBN>
<Publisher>Greenock</Publisher>
</Book>
<Book category="Art and design">
<Status>Available</Status>
<Title lang="en">The design of everyday things</Title>
<Author>
<Name>Donald Norman</Name>
<Genre>M</Genre>
</Author>
<Date>
<Day>27</Day>
<Month>02</Month>
<Year>2002</Year>
</Date>
<Price type="euro">26</Price>
<ISBN>8-4322-62332-6</ISBN>
<Publisher>Basic books</Publisher>
</Book>
I validated online the xml, and it is well formed. Next I made the schema:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Status">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="Available|Not available">
</xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Title">
<xsd:complexType>
<xsd:attribute name="en" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="Author" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Name">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-zA-Z]+\\s[a-zA-Z]+">
</xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Genre">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="M"/>
<xsd:enumeration value="F"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Date">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Day">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="31"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Month">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="12"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Year">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Price" type="xsd:decimal">
</xsd:element>
<xsd:element name="ISBN">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{1}-\d{5}-\d{3}-\d{1}|\d{1}-\d{3}-\d{5}-\d{1}|\d{1}-\d{2}-\d{6}-\d{1}">
</xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Publisher" type="xsd:string">
</xsd:element>
</xsd:sequence>
<xsd:attribute name="category" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
When i try to validate online this, i get the following errors: http://www.utilities-online.info/xsdvalidation/?save=72595340-b1e9-4061-a655-c6cfb9cdac44-xsdvalidation#.UsivXPQW1PI Click on button Validate xml against xsd and see all errors. Does anyone know to solve this without any error?
Upvotes: 0
Views: 446
Reputation: 111541
Now that the changes to the question appear to have quiesced, here is your XSD updated to eliminate the validation errors that you were receiving when validating the given XML document instance.
Fixed XSD:
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.books.org"
xmlns="http://www.books.org"
elementFormDefault="qualified">
<xsd:element name="BookStore">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Book" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Status">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="Available|Not available">
</xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Title">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="lang" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="Author" minOccurs="1" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Name">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="[a-zA-Z]+\s[a-zA-Z]+">
</xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Genre">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="M"/>
<xsd:enumeration value="F"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Date">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Day">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="31"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Month">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:minInclusive value="1"/>
<xsd:maxInclusive value="12"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Year">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Price">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:decimal">
<xsd:attribute name="type" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="ISBN">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\d{1}-\d{5}-\d{3}-\d{1}|\d{1}-\d{3}-\d{5}-\d{1}|\d{1}-\d{2}-\d{6}-\d{1}|\d{1}-\d{4}-\d{5}-\d{1}">
</xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="Publisher" type="xsd:string">
</xsd:element>
</xsd:sequence>
<xsd:attribute name="category" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
Minor note: I added another form to the ISBN pattern to support the ISBN for the last book: 8-4322-62332-6
. If this is not a valid ISBN format, you should eliminate the last |
-clause in the pattern that I added (\d{1}-\d{4}-\d{5}-\d{1}
) and instead fix the ISBN in the XML document instance.
Upvotes: 1