Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PROBLEM IN VALIDATING XML AGAINST AN XSD  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am stucked in getting my xml validated through an xsd
I am getting exception when i am executing my code to validate

xml
against
an xsd

Error:-----

org.jdom.JDOMException:

http://apache.org/xml/properties/schema/external-noNamespaceSchem

aLocation
property not

recognized for SAX driver org.apache.xerces.parsers.SAXParser

at

org.jdom.input.SAXBuilder.internalSetProperty(SAXBuilder.java:751

)at

org.jdom.input.SAXBuilder.setFeaturesAndProperties(SAXBuilder.jav

a:678)
at

org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:528)

at

org.jdom.input.SAXBuilder.build(SAXBuilder.java:424)at

org.jdom.input.SAXBuilder.build(SAXBuilder.java:891)at

XMLValidator.validateSchema(XMLValidator.java:39)at

XMLValidator.main(XMLValidator.java:85)

My Code:-----------

public class XMLValidator {
public void validateSchema(String SchemaUrl, String

XmlDocumentUrl) {
try {
SAXBuilder saxBuilder = new

SAXBuilder("org.apache.xerces.parsers.SAXParser", true);


saxBuilder.setValidation(true);
saxBuilder.setFeature(


"http://apache.org/xml/features/validation/schema", true);
/*error error in this

line*/saxBuilder.setFeature("http://apache.org/xml/features/valid

ation/schema-full-checking"

,true);


saxBuilder.setProperty("http://apache.org/xml/properties/schema/e

xternal-noNamespaceSchemaLo

cation",SchemaUrl); /* error in this line */
................

saxBuilder.build(XmlDocumentUrl);

/*throwing exception here

external-noNamespaceSchemaLocation property not recognized for

SAX
driver

org.apache.xerces.parsers.SAXParser*/




......................



public static void main(String[] argv) {
.............
}

}
-----------------------------------------------------------------

---------------
This is xml format i am creating using jdom parser:-----

<?xml version="1.0" encoding="UTF-8"?>
<cdm>


<report><R_id>1237</Rentity_id><code>India</code><R_code>STR</R_c

ode>
.......
</cdm>

This is xsd:--------------------------------------------

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" id="Cdm">
<xs:include schemaLocation="goNums.xsd"/>
<xs:element name="Cdm">


<xs:complexType>......................................

Please do reply

Regards

Zia
zia.uddin@yahoo.co.in
 
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any particular reason to use JDOM? Java 1.5 has the javax.xml.validation package in the standard library.

Bill
 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first of all: why are you shouting at us (->subject)?

as the preview post says, validation is included already in standard api. i am quite content with it. have a look at my code snippet. it should show you how it works.
 
Blueberry pie is best when it is firm and you can hold in your hand. Smell it. And smell this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!