<html>
<head>
<style>
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
FONT-SIZE: 10pt;
FONT-FAMILY:Tahoma
}
</style>
</head>
<body class='hmmessage'>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);">Unable to validate a JDOM document or element with the Schema class of jdom contrib package.</span></span></p><p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);"></span></span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);"></span></span></b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);">I make a customValidation method and i try to Validate a JDOM document. the problem is that <br></span></span></p><p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);"></span></span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);"><span>e</span></span></span></b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);"><span>very time I get an exception "</span></span></span><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">Failed to parse
schema "file:/C:/messages.xsd": no validation engine available </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">for</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">: http://www.w3.org/2001/XMLSchema.</span><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB"><span style="color: rgb(0, 0, 0);"><span>"<span style="font-weight: bold;"><br></span></span></span></span></p><p class="MsoNormal" style="">I have try to Parse the xsd with following String values but all the times I failed.</p><p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style="background: silver none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">String</span> uriFile = "C:/messages.xsd"</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style="background: silver none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><br></span></span></p><p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style="background: silver none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">String</span> uriFile = "</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">file:/C:/messages.xsd"</span></p><p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"></span>Below is the code and the xml,xsd.</p><p class="MsoNormal" style=""><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">public</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">void</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">
customValidation() </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">throws</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> JDOMException, IOException{</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span></span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">String</span> xmlFile = </span><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(42, 0, 255);" lang="EN-GB">"C:/messages.xml"</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">;</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span>SAXBuilder
builder = </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">new</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> SAXBuilder();</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span>Document
doc = builder.build(</span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">new</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> FileInputStream(xmlFile));</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span></span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">String</span> schemaFile = </span><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(42, 0, 255);" lang="EN-GB">"C:/messages.xsd"</span><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">;</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span>File file =
</span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">new</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> File(schemaFile);</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span></span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style="background: silver none repeat scroll 0%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;">String</span> uriFile =
file.toURL().toString();</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span>Schema
schema = Schema.<i>parse</i>( uriFile, Schema.</span><i><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 192);" lang="EN-GB">W3C_XML_SCHEMA</span></i><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">);</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span></span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span>List errors = schema.validate(doc);</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span></span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">if</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> (errors != </span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">null</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">) {</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span><span style=""> </span></span><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(63, 127, 95);" lang="EN-GB">// Validation errors</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span><span style=""> </span></span><b><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(127, 0, 85);" lang="EN-GB">for</span></b><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"> (Iterator
i=errors.iterator(); i.hasNext(); ) {</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span><span style="">
</span>ValidationError e = (ValidationError)(i.next());</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span><span style="">
</span>System.</span><i><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(0, 0, 192);" lang="EN-GB">out</span></i><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">.println(e);</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span><span style=""> </span><span style=""> </span>}</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span>}</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal" style=""><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span><span style=""> </span></span><span style="font-size: 10pt; font-family: "Courier New"; color: rgb(63, 127, 95);" lang="EN-GB">// Else: No error, document is valid.</span><span style="font-size: 10pt; font-family: "Courier New";" lang="EN-GB"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><span style=""> </span><span style=""> </span>}</span><span style="" lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"></span><span style="font-size: 10pt; font-family: Arial Black,Geneva,Arial,Sans-serif; color: black;" lang="EN-GB">messages.xml</span></p><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><?xml version="1.0" encoding="UTF-8"?><br><messages xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com messages.xsd"><br><br> <message id="first"><br> <english>first msg</english><br> <greek>first msg.</greek><br> </message><br> <br> <message id="second"><br> <english>second msg</english><br> <greek>second msg.</greek><br> </message><br> <br></messages><br></span></p><p class="MsoNormal"><br><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"></span></p><p style="font-weight: bold; font-family: Arial Black,Geneva,Arial,Sans-serif;" class="MsoNormal"><font size="5"><span style="font-size: 10pt; color: black;" lang="EN-GB">messages.xsd:</span></font></p><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><?xml version="1.0"?><br><br><xs:schema <br>xmlns:xs="http://www.w3.org/2001/XMLSchema"<br>xmlns="http://www.w3schools.com"<br>targetNamespace="http://www.w3schools.com"<br>elementFormDefault="qualified"><br><br><xs:element name="messages" ><br> <xs:complexType><br> <xs:sequence><br> <xs:element name="message" maxOccurs="unbounded"><br> <xs:complexType><br> <xs:sequence><br> <xs:element name="english" type="xs:string" minOccurs="0" /><br> <xs:element name="greek" type="xs:string" minOccurs="0" /><br> </xs:sequence><br> <xs:attribute name="id" type="xs:string" /><br> </xs:complexType><br> </xs:element><br> </xs:sequence><br> </xs:complexType><br></xs:element><br></xs:schema></span></p><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">Thanks in advance. <br></span></p><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB">John Dousaitis.<br></span></p><p class="MsoNormal"><span style="font-size: 10pt; font-family: "Courier New"; color: black;" lang="EN-GB"><br><o:p></o:p></span></p>
<br /><hr />Get news, entertainment and everything you care about at Live.com. <a href='http://www.live.com/getstarted.aspx ' target='_new'>Check it out!</a></body>
</html>