Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
JSP - A mailing list about Java Server Pages specification and reference
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
Problems on validating XML against Schema using JDOM

Problems on validating XML against Schema using JDOM

2006-11-08       - By M?rcio Nielsen Baptista

 Back
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 (See http://ISO-8859.ora-code.com)-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.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face=Arial size=2>Hi, </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I am trying to validate a xml against schema.<BR>I
have successfully validated the xml against the schema in XMLSpy. <BR>But when
i
am trying to validate it in my java code using JDOM, it is giving me the
following error: </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>"org.jdom.input.JDOMParseException: Error on line
1: cvc-elt.1: Cannot find the declaration of element 'Mensagem'." </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>I am using the following code: </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SAXBuilder sb = new
SAXBuilder("org.apache.xerces.parsers.SAXParser");<BR>&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
sb.setValidation(true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sb.setFeature("<A
href="http://apache.org/xml/features/validation/schema">http://apache.org/xml
/features/validation/schema</A>",
true);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sb.setProperty("<A
href="http://apache.org/xml/properties/schema/external-schemaLocation">http:/
/apache.org/xml/properties/schema/external-schemaLocation</A>",
"<A
href="http://localhost:8988/gofer/gofer.xsd">http://localhost:8988/gofer/gofer
.xsd</A>");</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
this.setDocumentoXML( sb.build( new StringReader(valorParam) ) ); </FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=Arial size=2>
<DIV><BR>gofer.xsd (Root Element): <BR>================= <BR>&lt;xs:schema
xmlns:xs="<A
href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</A>"
elementFormDefault="qualified" attributeFormDefault="unqualified"&gt;
<BR>&nbsp;&lt;xs:element name="Mensagem"&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV>xml String (Root Element) <BR>================= <BR>&lt;?xml version="1.0"
encoding="ISO-8859 (See http://ISO-8859.ora-code.com)-1" ?&gt;<BR>&nbsp;&lt;Mensagem xmlns:xsi="<A
href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001
/XMLSchema-instance</A>"
xsi:noNamespaceSchemaLocation="<A
href="http://localhost:8988/gofer/gofer.xsd">http://localhost:8988/gofer/gofer
.xsd</A>"
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;
identificador="L00196b6272223b453ed9844a8815ac7f2f9"&gt;</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>I am wondering if I am doing anything wrong. </DIV>
<DIV>&nbsp;</DIV>
<DIV>Thanks </DIV>
<DIV>&nbsp;</DIV>
<DIV>Marcio Nielsen Baptista. <BR></FONT></DIV></BODY></HTML>

__ ____ ____ ____ ____ ____ ____ ____ ____ ____
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.