SchemaFactory error

Hi

This piece of my code is throwing parsing exceptions

SchemaFactory sf = SchemaFactory.newInstance(NS_URI);

ClassLoader cl = JWebTools.class.getClassLoader();

URL url = cl.getResource(schema);//schema - method input

File f = new File(url.getPath());

try {// Debug code to see if the document is read

BufferedReader in = new BufferedReader(new FileReader(f));

String str=null;

while ((str = in.readLine()) != null) {

System.out.println(str);

}

in.close();

} catch (IOException e) {

} // Debug code end

return sf.newSchema(f);

Thewhile loop is able to print the schema file, but when I returnsf, it throws SAXParsing exception

JWeb is the application name

This is the exception -

org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'file:///C:/Program%20Files/JWeb/jboss-4.0.2/server/default/deploy/jweb.ear/jweb-ejb.jar/resources.xsd', because 1)

could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

Where is it going wrong?

Is there something to do with the classloader?

The ear as a file is working well, but when I explode it (put individual files into jweb.ear directory), it throws this error.

All help is greatly appreciated.

Thank you

[1434 byte] By [sridhar_rreddya] at [2007-11-27 4:15:44]
# 1

I think the problem is due to the white space in Program Files directory name.

Use this instead:

...

URL url = cl.getResource(schema);//schema - method input

File f = new File(url.getPath().replaceAll("%20", " "));//Changes here

...

Hope That Helps

java_2006a at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 2
Yet the same error. Your solution was to read the file. Problem here is I am able to read the file but SchemaFactory.newSchema() is not creating a schema object.And this happens only when the ear is exploded.
sridhar_rreddya at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 3
> The ear as a file is working well, but when I explode> it (put individual files into jweb.ear directory),> it throws this error.What do you mean by "put individual files into"? Are you manually changing something or some file location?
karma-9a at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 4

> > The ear as a file is working well, but when I

> explode

> > it (put individual files into jweb.ear

> directory),

> > it throws this error.

>

> What do you mean by "put individual files into"?

> Are you manually changing something or some file

> location?

Individual files means the class files, property files and xml, xsd files all make a application which in general are archived into a ear file.

Exploding it means, ear file will become ear directory(i.e. jweb.ear file will become jweb.ear directory and all files archived in the ear file will be put inside the directory as individual files.

sridhar_rreddya at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 5

> > > The ear as a file is working well, but when I

> > explode

> > > it (put individual files into jweb.ear

> > directory),

> > > it throws this error.

> >

> > What do you mean by "put individual files into"?

> > Are you manually changing something or some file

> > location?

>

> Individual files means the class files, property

> files and xml, xsd files all make a application which

> in general are archived into a ear file.

> Exploding it means, ear file will become ear

> directory(i.e. jweb.ear file will become jweb.ear

> directory and all files archived in the ear file will

> be put inside the directory as individual files.

? Thank you, I know what an exploded .ear file is.

What I meant is, are you changing the structure of the exploded .ear manually in any way? Are you adding, moving files, after the .ear file is exploded?

karma-9a at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 6
No. Things are in place. I just exploded them...thats it. Nothing else. Inside the ear, theres a jweb-ejb.jar which is also exploded to jweb-ejb.jar dir replacing its parent file(jweb-ejb.jar).
sridhar_rreddya at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 7

> This is the exception -

> org.xml.sax.SAXParseException: schema_reference.4:

> Failed to read schema document

> 'file:///C:/Program%20Files/JWeb/jboss-4.0.2/server/de

> fault/deploy/jweb.ear/jweb-ejb.jar/resources.xsd',

> because 1)

> could not find the document; 2) the document could

> not be read; 3) the root element of the document is

> not <xsd:schema>.

The problem seems to be where you're specifying the schema location (not the xml file itself) in the root element. For example, with :

<your_root_element

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:noNamespaceSchemaLocation="your_schema.xsd">

your_schema.xsd would be in the same folder than the xml file referencing it.

karma-9a at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...
# 8
I think theres a problem in SchemaFactory API. So instead of building file object from a URI, I did it by streaming.
sridhar_rreddya at 2007-7-12 9:22:07 > top of Java-index,Java Essentials,Java Programming...