[jdom-interest] Parsing AND validating a schema
Paul Cooper
paul_cooper_premis at hotmail.com
Mon Jan 24 14:30:29 PST 2005
I've searched and searched, and tried all sorts of combinations of features
and properties, and I cannot figure out how to validate a schema. Yes,
that's right, a schema. I'm trying to treat the schema as if it were an
actual XML file, and parsing is no problem. But validation is, so I'm hoping
someone can provide insight. I'm pointing the schema for my schema to the
correct location, BTW.
Here's my code:
private static void init(InputStream is) throws IOException, JDOMException {
BufferedReader br = new BufferedReader(new InputStreamReader(is,
"UTF8"));
SAXBuilder builder = new
SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
builder.setIgnoringElementContentWhitespace(true);
builder.setFeature("http://apache.org/xml/features/validation/schema",
true);
builder.setFeature("http://xml.org/sax/features/namespaces", true);
builder.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
builder.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
"http://www.w3.org/2001/XMLSchema.xsd");
_document = builder.build(br);
br.close();
}
I won't post the whole schema here, but it dies on the first line:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="AbdomenLeftUpperAssessment">
<xs:annotation>
<xs:documentation>The assessment of the patients left upper
abdomen</xs:documentation>
</xs:annotation>
</xs:simpleType>
</xs:schema>
The exception I get:
org.jdom.input.JDOMParseException: Error on line 3: cvc-elt.1: Cannot find
the declaration of element 'xs:schema'.
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:468)
at org.jdom.input.SAXBuilder.build(SAXBuilder.java:851)
at org.premis.xml.PreMISDocument.init(PreMISDocument.java:50)
at org.premis.xml.PreMISDocument.create(PreMISDocument.java:66)
at org.premis.nemsis.Reader.doIt(Reader.java:29)
at org.premis.nemsis.Reader.main(Reader.java:54)
Clearly this is a namespace issue, but for the life of me I cannot figure
out what the parser wants. Can anyone shed some light into this dilemma???
Thanks,
Paul Cooper
_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement
More information about the jdom-interest
mailing list