G
Ghee
Dear comp.text.xml,
I'm trying (in Java) to get a DOM parser to validate a document on
parsing - but I don't seem to get what I expect. I've used XMLSPY to
verify the doc and schema. When I try to parse and validate the doc, I
get messages about trying to find a DTD(?) - "Valid documents must have
a <!DOCTYPE declaration." - but I want an xml schema, not a DTD. I
then get warnings about each and every element/attribute/etc not being
declared. It's as if it's ignoring the setAttribute call to set the
schema language. Here's the code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
String schemaSource = "C:/risk.xsd";
String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
factory.setAttribute(JAXP_SCHEMA_SOURCE, new File(schemaSource));
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(err_handler);
document = builder.parse( new File("C:/risk.xml") );
What am I doing wrong???
Thanks for any help,
Ghee
I'm trying (in Java) to get a DOM parser to validate a document on
parsing - but I don't seem to get what I expect. I've used XMLSPY to
verify the doc and schema. When I try to parse and validate the doc, I
get messages about trying to find a DTD(?) - "Valid documents must have
a <!DOCTYPE declaration." - but I want an xml schema, not a DTD. I
then get warnings about each and every element/attribute/etc not being
declared. It's as if it's ignoring the setAttribute call to set the
schema language. Here's the code:
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
String schemaSource = "C:/risk.xsd";
String JAXP_SCHEMA_SOURCE =
"http://java.sun.com/xml/jaxp/properties/schemaSource";
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
factory.setAttribute(JAXP_SCHEMA_SOURCE, new File(schemaSource));
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(err_handler);
document = builder.parse( new File("C:/risk.xml") );
What am I doing wrong???
Thanks for any help,
Ghee