3 Replies Latest reply: Jul 16, 2010 7:25 AM by 843789 RSS

    Problem with file path

    843789
      Hi!
      I have this problem: if I write
      public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
          String defaultXsd = "file:///D:/work/workspace/example/data/cars.xsd";
          if (systemID.equals(sysID)) {
            return new InputSource(defaultXsd);
          } else {
            return null;
          }
        }
      everything works fine, but with this:
      public InputSource resolveEntity(String publicID, String systemID) throws IOException, SAXException {
          String defaultXsd = "data/cars.xsd";
          if (systemID.equals(sysID)) {
            return new InputSource(defaultXsd);
          } else {
            return null;
          }
        }
      I have an exception. Where can be the problem? I can't have absoluth path there:(
        • 1. Re: Problem with file path
          843789
          Those are String values. You compare a single String value to two different constants.

          For one comparison it returns true, for the other one, it returns false.

          Why exactly is that a surprise?

          They systemID given to you here is simply the value as stated in the XML. Only if you don't return anything here, will the value be interpreted as an URI. Until then you get a verbatim copy of what was specified.
          • 2. Re: Problem with file path
            843789
            But my question is about creating that InputSource. The problem is, that when I state absolute path to .xsd file ("file:///D:/work/workspace/example/data/cars.xsd") everything works, but when I set relative path ("data/cars.xsd") it doesn't. And I can't have absolute path there.
            • 3. Re: Problem with file path
              843789
              I've got it: String defaultXsd = "file:./data/cars.xsd";