Hi,

You are correct, I should be using the noNamespaceSchemaLocation. I switched to that, but I am getting the same error. I read the link that you sent over. All of that makes sense except that the schema I am loading is not coming from a web url. It is a local file that is in the classpath. The relative path from the classpath root is the only way to locate the schema file..which is what I seem to be having difficulties with. Thanks.

~Mike

Michael Glavassevich wrote:

Hi Michael,

The external schema location properties have the same definitions as the ones defined in the schema spec [1]. The value of schemaLocation is a list of pairs of URIs, where the first of each pair is a target namespace and the second of each pair is a schema location hint. You've only specified a location. Does your schema have a target namespace? If it doesn't have one you should be using the noNamespaceSchemaLocation property instead.

[1] http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#schema-loc

Michael MacFadden <[EMAIL PROTECTED]> wrote on 01/04/2005 01:09:39 PM:



All,

I have a question about schema validation. I have a feeling that this is something that gets asked a lot but, I haven't been able to find the exact use case that I need help with.

Basically, the project I am working on uses xml to store project data that get generated by our tool. I have created a schema to validate this project xml file. The schema is going to be shipped with the product and will be in the CLASSPATH (possibly in a jar file). I am wondering how I can tell the parser to use the schema file to validate the project file. I would rather not have to specify the schema in the xml of the project file, because then some one could remove the schema declaration. So basically, I want to configure the parser to use a schema that is in the CLASSPATH.

From the java code, the only way I can reference the schema file is something like "/org/foo/schema/project.xsd". This is because I don't know the absolute path of the file I just know that it is in the classpath. I have tried to use the ClassLoader's getResource() method to get the URL of the xsd file, but it still doesn't seem top be working. Can some one point me to an example of how to do this.

Here is what I have that isn't working.

try
{
ClassLoader cl = ConnectionFileParser.class.getClassLoader();
URL url = cl.getResource( CONN_SCHEMA_FILE );
DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/validation";,


true);


parser.setFeature("http://xml.org/sax/features/namespaces";,

true);


parser.setFeature("http://apache.org/xml/features/validation/schema";,

true);


       parser.setProperty(

"http://apache.org/xml/properties/schema/external-schemaLocation";,
             url.getFile() );
       parser.setErrorHandler( eh );
       parser.parse( source );
}

if( !eh.isValid() )
{
throw new IOException( "There were errors when parsing the XML file:


\n"


                       + eh.getErrorList() );
}


After parsing, the error handler object contains an error of "Line 3: cvc-elt.1: Cannot find the declaration of element 'Connection'." Which is the root element of the project file. I could be doing this completely wrong. Any help would be great. Thanks


~Mike


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




Michael Glavassevich XML Parser Development IBM Toronto Lab E-mail: [EMAIL PROTECTED] E-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to