  | 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
|
|
|
  | | | 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> </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> </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> </DIV> <DIV><FONT face=Arial size=2>I am using the following code: </FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2> SAXBuilder sb = new SAXBuilder("org.apache.xerces.parsers.SAXParser");<BR> sb.setValidation(true);<BR> sb.setFeature("<A href="http://apache.org/xml/features/validation/schema">http://apache.org/xml /features/validation/schema</A>", true);<BR> 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> </DIV> <DIV><FONT face=Arial size=2> this.setDocumentoXML( sb.build( new StringReader(valorParam) ) ); </FONT></DIV> <DIV> </DIV><FONT face=Arial size=2> <DIV><BR>gofer.xsd (Root Element): <BR>================= <BR><xs:schema xmlns:xs="<A href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</A>" elementFormDefault="qualified" attributeFormDefault="unqualified"> <BR> <xs:element name="Mensagem"></DIV> <DIV> </DIV> <DIV>xml String (Root Element) <BR>================= <BR><?xml version="1.0" encoding="ISO-8859 (See http://ISO-8859.ora-code.com)-1" ?><BR> <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> identificador="L00196b6272223b453ed9844a8815ac7f2f9"></DIV> <DIV> </DIV> <DIV><BR>I am wondering if I am doing anything wrong. </DIV> <DIV> </DIV> <DIV>Thanks </DIV> <DIV> </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)
|
|
 |