OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xml schema validation ?


Mandeep Bhatia wrote:

Hi List,
I am new to list and XML.

I am looking for a sample xml document and its schema which validates that
an element should not be null

i.e <book>
       <author></author> ' now if author is not null this should not be allowed
                                    there should be valid text in <author> element.
       <price>23</price> ' price should always be greater than 0.

can somebody send me an xml document and its schema which meets conditions like ones in above document.

Here is a sample XML (yours above) and a W3C XML Schema which will validate the way you want (If I understood the question correct).

XML Schema (book.xsd):

<xsd:schema xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" elementFormDefault="qualified" targetNamespace="http://www.test.org/book" xmlns="http://www.test.org/book">
 <xsd:element name="book">
    <xsd:element name="author">
      <xsd:restriction base="xsd:string">
       <xsd:minLength value="1"/>
    <xsd:element name="price">
      <xsd:restriction base="xsd:positiveInteger">
       <xsd:minExclusive value="0"/>

Instance (book.xml):

<book xmlns="http://www.test.org/book" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xsi:schemaLocation="http://www.test.org/book book.xsd">

The above schema will validate that the content of the author element must be a string with length greater than 0. Maybe you want to change the type of the price to decimal instead of positiveInteger to allow values like 23.45.

Hope this helps