[XML-DEV Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: xml schema validation ?
- From: Eddie Robertsson <eddie@a...>
- To: Mandeep Bhatia <mbhatia@M...>
- Date: Thu, 15 Mar 2001 09:58:31 +1100
Mandeep Bhatia wrote:
Hi List,
I am new to list and XML.
Welcome!
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.
</book>
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:complexType>
<xsd:sequence>
<xsd:element name="author">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="price">
<xsd:simpleType>
<xsd:restriction base="xsd:positiveInteger">
<xsd:minExclusive value="0"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
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">
<author>Eddie</author>
<price>23</price>
</book>
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
/Eddie
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|
Stylus Studio has published XML-DEV in RSS and ATOM formats,
enabling users to easily subcribe to the list from their preferred news reader application.
|
Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website.
they were not included by the author in the initial post. To view the content without the Sponsor Links please
click here.
|
|