[castor-dev] XML Validation with its XSD Schema when marshalling and unmarshalling
J p <[email protected]> Mon, 28 May 2012 06:24:14 +0530
| Newsgroups | gmane.comp.java.castor.devel |
|---|---|
| Message-ID | <CAGDpBkennWd-1F19uL+07t1q5hi6qrbLtbeq5TALPJh+WX4iTg@mail.gmail.com> |
--047d7b33dbec32873204c10e2839
Content-Type: text/plain; charset=ISO-8859-1
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?
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
--047d7b33dbec32873204c10e2839
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hi Werner,<br><br>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?<br><br>am working on this since last last week. below =
is xml and xsd files. <br>
<br>Book.xml :<br><br><?xml version=3D"1.0" encoding=3D"U=
TF-8"?><br><br><books xmlns:xsi=3D"<a href=3D"http://www.w3=
.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>=
"<br>
=A0=A0=A0 =A0=A0 xsi:NamespaceSchemaLocation=3D'books.xsd'><br>=
=A0=A0 <book id=3D"bk001"><br>=A0=A0=A0=A0=A0 <author>=
;Writer</author><br>=A0=A0=A0=A0=A0 <title>The First Book</t=
itle><br>=A0=A0=A0=A0=A0 <genre>Fiction</genre><br>
=A0=A0=A0=A0=A0 <price>44.95</price><br>=A0=A0=A0=A0=A0 <pub=
_date>2000-10-01</pub_date><br>=A0=A0=A0=A0=A0 <review>An am=
azing story of nothing.</review><br>=A0=A0 </book><br><br>=A0=
=A0 <book id=3D"bk002"><br>
=A0=A0=A0=A0=A0 <author>Poet</author><br>=A0=A0=A0=A0=A0 <ti=
tle>The Poet's First Poem</title><br>=A0=A0=A0=A0=A0 <genre=
>Poem</genre><br>=A0=A0=A0=A0=A0 <price>24.95</price><=
br>=A0=A0=A0=A0=A0 <review>Least poetic poems.</review><br>
=A0=A0 </book><br></books><br><br><br>XSD :<br><br><?xml ver=
sion=3D"1.0" encoding=3D"UTF-8"?><br><xsd:schema =
xmlns:xsd=3D"<a href=3D"http://www.w3.org/2001/XMLSchema">http://www.w=
3.org/2001/XMLSchema</a>"<br>
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 targetNamespace=3D"urn:books"<b=
r>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 xmlns:bks=3D"urn:books"><b=
r><br>=A0 <xsd:element name=3D"books" type=3D"bks:BooksFo=
rm"/><br><br>=A0 <xsd:complexType name=3D"BooksForm"&g=
t;<br>
=A0=A0=A0 <xsd:sequence><br>=A0=A0=A0=A0=A0 <xsd:element name=3D&q=
uot;book" <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 type=
=3D"bks:BookForm" <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0 minOccurs=3D"0" <br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 maxOccurs=3D"unbounded"/><br>
=A0=A0=A0=A0=A0 </xsd:sequence><br>=A0 </xsd:complexType><br><b=
r>=A0 <xsd:complexType name=3D"BookForm"><br>=A0=A0=A0 <=
xsd:sequence><br>=A0=A0=A0=A0=A0 <xsd:element name=3D"author&quo=
t;=A0=A0 type=3D"xsd:string"/><br>
=A0=A0=A0=A0=A0 <xsd:element name=3D"title"=A0=A0=A0 type=3D&q=
uot;xsd:string"/><br>=A0=A0=A0=A0=A0 <xsd:element name=3D"g=
enre"=A0=A0=A0 type=3D"xsd:string"/><br>=A0=A0=A0=A0=A0 &=
lt;xsd:element name=3D"price"=A0=A0=A0 type=3D"xsd:float&quo=
t; /><br>
=A0=A0=A0=A0=A0 <xsd:element name=3D"pub_date" type=3D"xs=
d:date" /><br>=A0=A0=A0=A0=A0 <xsd:element name=3D"review&q=
uot;=A0=A0 type=3D"xsd:string"/><br>=A0=A0=A0 </xsd:sequenc=
e><br>=A0=A0=A0 <xsd:attribute name=3D"id"=A0=A0 type=3D&qu=
ot;xsd:string"/><br>
=A0 </xsd:complexType><br></xsd:schema><br><br>Thanks,<br>John<=
br>
--047d7b33dbec32873204c10e2839--