Re: [castor-dev] XML Validation with its XSD Schema when marshalling and unmarshalling
Werner Guttmann <[email protected]> Mon, 04 Jun 2012 12:34:03 +0200
| Newsgroups | gmane.comp.java.castor.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi,
On 28.05.2012 02:54, J p wrote:
> Hi Werner,
>
> i neeed to validate pojo xml ( not mapping xml ) with its xsd when
> marshalling and unmarshalling with castor. How can i validate xml with
> xsd on castor?
Why don't you generate java sources from the XML schema, and rely on
Castor and its generated descriptor/validator code for validation ?
Kind Regards
Werner
>
> am working on this since last last week. below is xml and xsd files.
>
> Book.xml :
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <books xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:NamespaceSchemaLocation='books.xsd'>
> <book id="bk001">
> <author>Writer</author>
> <title>The First Book</title>
> <genre>Fiction</genre>
> <price>44.95</price>
> <pub_date>2000-10-01</pub_date>
> <review>An amazing story of nothing.</review>
> </book>
>
> <book id="bk002">
> <author>Poet</author>
> <title>The Poet's First Poem</title>
> <genre>Poem</genre>
> <price>24.95</price>
> <review>Least poetic poems.</review>
> </book>
> </books>
>
>
> XSD :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> targetNamespace="urn:books"
> xmlns:bks="urn:books">
>
> <xsd:element name="books" type="bks:BooksForm"/>
>
> <xsd:complexType name="BooksForm">
> <xsd:sequence>
> <xsd:element name="book"
> type="bks:BookForm"
> minOccurs="0"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <xsd:complexType name="BookForm">
> <xsd:sequence>
> <xsd:element name="author" type="xsd:string"/>
> <xsd:element name="title" type="xsd:string"/>
> <xsd:element name="genre" type="xsd:string"/>
> <xsd:element name="price" type="xsd:float" />
> <xsd:element name="pub_date" type="xsd:date" />
> <xsd:element name="review" type="xsd:string"/>
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:string"/>
> </xsd:complexType>
> </xsd:schema>
>
> Thanks,
> John
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email