[jdom-interest] Problems on validating XML against Schema using JDOM

Márcio Nielsen Baptista marcio.nielsen at vgainfo.com
Wed Nov 8 10:12:11 PST 2006


Hi, 

I am trying to validate a xml against schema.
I have successfully validated the xml against the schema in XMLSpy. 
But when i am trying to validate it in my java code using JDOM, it is giving me the following error: 

"org.jdom.input.JDOMParseException: Error on line 1: cvc-elt.1: Cannot find the declaration of element 'Mensagem'." 

I am using the following code: 

      SAXBuilder sb = new SAXBuilder("org.apache.xerces.parsers.SAXParser");
      sb.setValidation(true);
      sb.setFeature("http://apache.org/xml/features/validation/schema", true);
      sb.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", "http://localhost:8988/gofer/gofer.xsd");

      this.setDocumentoXML( sb.build( new StringReader(valorParam) ) ); 


gofer.xsd (Root Element): 
================= 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> 
 <xs:element name="Mensagem">

xml String (Root Element) 
================= 
<?xml version="1.0" encoding="ISO-8859-1" ?>
 <Mensagem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://localhost:8988/gofer/gofer.xsd" 
                 identificador="L00196b6272223b453ed9844a8815ac7f2f9">


I am wondering if I am doing anything wrong. 

Thanks 

Marcio Nielsen Baptista. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.jdom.org/pipermail/jdom-interest/attachments/20061108/870f976e/attachment.htm


More information about the jdom-interest mailing list