Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

xml schema validation with xerces and jdom

843834Sep 12 2006 — edited Sep 12 2006
hi everybody,

i have a problem which really drives me mad:

i use:

- java 1.4
- jdom 1.0
- xerces

Now i want to validate an existing xml-file against an existing xml-schema:

the jdom.org faq has the following example:
SAXBuilder builder =
  new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setFeature(
  "http://apache.org/xml/features/validation/schema", true);
builder.setProperty(
  "http://apache.org/xml/properties/schema/external-schemaLocation",
  "http://www.w3.org/2001/12/soap-envelope soap-envelope.xsd" + " " +
  "http://kevinj.develop.com/weblog/weblog.xsd weblog.xsd");
Document doc = builder.build(xml);
Thats exactly how i am doing it, here is my code:
		SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
		
		saxBuilder.setFeature("http://apache.org/xml/features/validation/schema", true);
		
		saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", 
								new File("C:/projects/trcs/prozesse/tenderml/rfq.xsd").toURI().toString());
		
		
		try {
			saxBuilder.build(new StringReader(tenderML));
		} catch (JDOMException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
Unfortunately, if i try to validate it with the code above i get the error:
rg.jdom.input.JDOMParseException: Error on line 2: cvc-elt.1: Cannot find the declaration of element 'tender'.
'tender' is my root element in the xml-file.

here is an excerpt of the xml-file:
<?xml version="1.0" encoding="UTF-8"?>
<tender xmlns="trcs">
   <internal>
      <called_datetime>2002-12-31T12:00:00</called_datetime>
      <insert_datetime>2002-12-31T12:00:00</insert_datetime>
and here the beginning of the xml-scheme (which was validated by the w3c-validator):
<?xml version="1.0" encoding="UTF-8"?>
<trcs:schema xmlns:trcs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">

<!--		RFQ		-->

<trcs:element name="tender">
	<trcs:complexType>
		<trcs:sequence>
		
			<!-- internal -->

			<trcs:element name="internal">
				<trcs:complexType>
					<trcs:sequence>
						<!-- dateTime -->
						<trcs:element name="called_datetime" type="trcs:dateTime" default="0000-00-00T00:00:00" />
						<trcs:element name="insert_datetime" type="trcs:dateTime" default="0000-00-00T00:00:00" />
One strange thing:

if i change
		saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation", 
								new File("C:/projects/trcs/prozesse/tenderml/rfq.xsd").toURI().toString());
to
saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
								new File("C:/projects/trcs/prozesse/tenderml/rfq.xsd").toURI().toString());
i.e. i tell the parser that my scheme has no namespace it works...

WTF is wrong?

I really dont get it, any help on this subject is really appreciated scince i have been trying for hours...........

Message was edited by:
buggybunny
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2006
Added on Sep 12 2006
0 comments
345 views