[jdom-interest] Unable to validate a JDOM document or element
with the Schema class of jdom contrib package.
Laurent Bihanic
laurent.bihanic at atosorigin.com
Mon Sep 1 14:33:55 PDT 2008
Hi,
You only have the schema validation API in the classpath (isorelax.jar) but no
implementation. None is provided with JDOM contrib.
You can use Sun's Multi-Schema XML Validator that can be found at
https://msv.dev.java.net/
Regards,
Laurent
John Dous a écrit :
> Unable to validate a JDOM document or element with the Schema class of
> jdom contrib package.
>
> **I make a customValidation method and i try to Validate a JDOM
> document. the problem is that
>
> *e*very time I get an exception "Failed to parse schema
> "file:/C:/messages.xsd": no validation engine available *for*:
> http://www.w3.org/2001/XMLSchema."
>
> I have try to Parse the xsd with following String values but all the
> times I failed.
>
> String uriFile = "C:/messages.xsd"
>
> String uriFile = "file:/C:/messages.xsd"
>
> Below is the code and the xml,xsd.
>
> *public* *void* customValidation() *throws* JDOMException, IOException{
>
>
>
> String xmlFile = "C:/messages.xml";
>
> SAXBuilder builder = *new* SAXBuilder();
>
> Document doc = builder.build(*new* FileInputStream(xmlFile));
>
>
>
> String schemaFile = "C:/messages.xsd";
>
> File file = *new* File(schemaFile);
>
>
>
> String uriFile = file.toURL().toString();
>
> Schema schema = Schema./parse/( uriFile, Schema./W3C_XML_SCHEMA/);
>
>
>
> List errors = schema.validate(doc);
>
> *if* (errors != *null*) {
>
> // Validation errors
>
> *for* (Iterator i=errors.iterator(); i.hasNext(); ) {
>
> ValidationError e = (ValidationError)(i.next());
>
> System./out/.println(e);
>
> }
>
> }
>
> // Else: No error, document is valid.
>
> }
>
>
>
> messages.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <messages xmlns="http://www.w3schools.com"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://www.w3schools.com messages.xsd">
>
> <message id="first">
> <english>first msg</english>
> <greek>first msg.</greek>
> </message>
>
> <message id="second">
> <english>second msg</english>
> <greek>second msg.</greek>
> </message>
>
> </messages>
>
>
> messages.xsd:
>
> <?xml version="1.0"?>
>
> <xs:schema
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="http://www.w3schools.com"
> targetNamespace="http://www.w3schools.com"
> elementFormDefault="qualified">
>
> <xs:element name="messages" >
> <xs:complexType>
> <xs:sequence>
> <xs:element name="message" maxOccurs="unbounded">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="english" type="xs:string"
> minOccurs="0" />
> <xs:element name="greek" type="xs:string"
> minOccurs="0" />
> </xs:sequence>
> <xs:attribute name="id" type="xs:string" />
> </xs:complexType>
> </xs:element>
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> </xs:schema>
>
> Thanks in advance.
>
> John Dousaitis.
>
>
>
> ------------------------------------------------------------------------
> Get news, entertainment and everything you care about at Live.com. Check
> it out! <http://www.live.com/getstarted.aspx >
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
--
wWw
(o o)
-------------ooO-(_)-Ooo-----------------------------------------------
Laurent Bihanic | Tel: +33 (0)1 55 91 24 95 (direct)
Division Finance | +33 (0)1 55 91 20 00
Atos Origin System Integration | Mob: +33 (0)6 25 73 03 74
Les Miroirs - Bat. C | Fax: +33 (0)1 70 92 12 47
18, avenue d'Alsace |
F-92926 La Defense Cedex | mailto: laurent.bihanic at atosorigin.com
-----------------------------------------------------------------------
Very funny, Scotty. Now beam down my clothes.
Please consider your environmental responsibility before printing
this e-mail.
DISCLAIMER:
The opinions expressed are entirely my own and may not necessarily be
those of my employer. Also, I am not now nor have I ever been a
lawyer. My opinions are provided as-is with absolutely no warrantee of
merchantability or fitness for any particular use. Besides, you can't
prove I typed this. No body saw me type this. Who says I typed this?
More information about the jdom-interest
mailing list