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

Discussion in 'XML' started by thefirstwml, Apr 19, 2004.

  1. thefirstwml

    thefirstwml Guest

    I figured out that the relative path is to the Java classpath, not to relative
    to where the XML files are located!

    (thefirstwml) wrote in message news:<>...
    > 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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xsi:noNamespaceSchemaLocation="aSchema.xsd">
    >
    > I have to change that to:
    > <?xml version="1.0" encoding="windows-1252" ?>
    > <InstrumentList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > 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("http://xml.org/sax/features/namespaces"; true);
    > // Tell Parser to Validate
    > parser.setFeature("http://xml.org/sax/features/validation", true);
    >
    > // Tell Parser to Validate using schema, above line is required as
    > well
    > parser.setFeature("http://apache.org/xml/features/validation/schema",
    > 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?
     
    thefirstwml, Apr 19, 2004
    #1
    1. Advertising

  2. Make sure to set the 'systemId' in the InputSource.

    Edwin
     
    Edwin Dankert, Apr 19, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    452
    John Timney \(ASP.NET MVP\)
    Apr 8, 2005
  2. Matt
    Replies:
    3
    Views:
    19,626
    Sudsy
    Jul 8, 2004
  3. Markus
    Replies:
    1
    Views:
    1,614
    Markus
    Nov 23, 2005
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,296
    Stanimir Stamenkov
    Apr 25, 2005
  5. shawnk
    Replies:
    0
    Views:
    406
    shawnk
    Apr 29, 2005
Loading...

Share This Page