Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: How do you use a Relative Path to locate a Schema using Java?

Thread Tools

Re: How do you use a Relative Path to locate a Schema using Java?

Posts: n/a
I figured out that the relative path is to the Java classpath, not to relative
to where the XML files are located! Removed) (thefirstwml) wrote in message news:<(E-Mail Removed). com>...
> Hi, I am using a Xerces 2.6.1 XML Parser. I want to parse XML data
> and
> populate a relational database. I have figured out how to validate
> the XML
> data using a schema, but I have to modify the XML data files so that
> the schema location uses an absolute path, otherwise, the application
> runs and I receive an error that the first element, InstrumentList,
> cannot be found even though
> the xml file is in the same directory as the schema file.
> Here is a sample of the header in each file:
> <?xml version="1.0" encoding="windows-1252" ?>
> <InstrumentList xmlnssi=""
> xsi:noNamespaceSchemaLocation="aSchema.xsd">
> I have to change that to:
> <?xml version="1.0" encoding="windows-1252" ?>
> <InstrumentList xmlnssi=""
> xsi:noNamespaceSchemaLocation="file:///C:/aSchema.xsd">
> ---------------------------------------------------------------
> Here is a sample XML code that I am using:
> XMLReader parser = XMLReaderFactory.createXMLReader();
> // tell parser to be namespace aware
> parser.setFeature(""; true);
> // Tell Parser to Validate
> parser.setFeature("", true);
> // Tell Parser to Validate using schema, above line is required as
> well
> parser.setFeature("",
> true);
> // Instantiate this class to provide handlers for the parser and
> // tell the parser about the handlers
> parser.setContentHandler(this);
> parser.setErrorHandler(this);
> // Create an input source that describes the file to parse.
> // Then tell the parser to parse input from that source
> FileReader fr = new FileReader(eRegFile);
> InputSource input = new InputSource(fr);
> LogUtil.debug(this.getClass(), "Before Parse");
> parser.parse(input);
> I tried setting the namespaces feature to false, but that does not
> work either.
> What do I need to do to use the relative path instead of an absolute
> path?

Reply With Quote
Edwin Dankert
Posts: n/a
Make sure to set the 'systemId' in the InputSource.


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Hosts file to locate schema for validation shawnk XML 0 04-29-2005 02:16 PM
[XML Schema] Including a schema document with absent target namespace to a schema with specified target namespace Stanimir Stamenkov XML 3 04-25-2005 09:59 AM
Can aspx file use PATH variable to locate dlls ASP .Net 1 04-08-2005 09:33 PM
absolute path versus relative path in JSP Matt Java 3 07-08-2004 08:31 PM
Make a relative url path from an absolute path to another one Thomas Guettler Python 3 10-27-2003 04:41 PM