How to specify file on local disk with external schema

P

pohmart

I am using Xerces 2.6.2 and SAX on Windows2k. I want to validate an XML
doc, which has no schema reference,
with an external schema which is on my PC.

I am setting the following properties and features:
saxParser.setFeature("http://xml.org/sax/features/namespaces", true);
saxParser.setFeature("http://xml.org/sax/features/namespace-prefixes",
true);
saxParser.setFeature("http://xml.org/sax/features/validation", true);
saxParser.setFeature("http://apache.org/xml/features/validation/schema",
true);
saxParser.setFeature("http://apache.org/xml/features/standard-uri-conformant",
false);
saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",

"file:///C:/test/testSchema.xsd");

When I parse the document the parser is unable to locate the schema
document.
I have tried several variations for the URL to the schema file such as:
file://localhost/C:/test/testSchema.xsd
C:/test/testSchema.xsd
file:///C|/test/testSchema.xsd

but nothing works.
Can anyone tell me the correct way to do this?
Thanks in advance,
Paul
 
R

Romin

In your last statement, you have mentioned:

saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
"file:///C:/test/testSchema.xsd");

which is not correct. You need to specify the second parameter
as "TARGETNAMESPACE SCHEMAFILELOCATION"

So, your TARGETNAMESPACE=http://mydomain.com/ns
and your SCHEMAFILELOCATION=file:///c:/test/testSchema.xsd

So -- your last statement should be:
saxParser.setProperty("http://apache.org/xml/properties/schema/external-schemaLocation",
"http://mydomain.com/ns file:///C:/test/testSchema.xsd");

You should be able to get your targetnamespace value from the XSD file
that you have.

Hope this helps...
Romin.
 
P

pohmart

Romin,
That did it. Thank you so much for both taking time out to reply and
for the wonderfull clarity. It helped enormously!
Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top