Title: schemaLocation without using absolute path

Does anyone know how I could allow the validation to work if my first xsd include a second xsd without specifying the absolute path of the second.xsd such as

<xsd:include schemaLocation="file:///c:/temp/second.xsd"/> ?

Below is the example.  A test.xml refers to the c:/temp/first.xsd which includes a second.xsd that is also located in c:/temp directory.

<!-- first.xsd -->
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://www.xxx.com"
     xmlns="http://www.xxx.com"
     elementFormDefault="qualified">

  <xsd:include schemaLocation="second.xsd"/>
  
  <xsd:element name="root">
     ...
  </xsd:element>
</xsd:schema>

<!-- second.xsd -->
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
     targetNamespace="http://www.xxx.com"
     xmlns="http://www.xxx.com"
     elementFormDefault="qualified">
   ...
</xsd:schema>

<!-- test.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.xxx.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:schemaLocation="http://www.xxx.com file:///c:/temp/first.xsd">

   ...
</root>

The validation works fine if I use DOMParser.parse(new File("c:/temp/test.xml")).  But if the test.xml is an XML string instead, it will fail to locate the second.xsd as I did not specify the absolute path of the second.xsd.  Here is the code.

        StringReader stringReader = new StringReader(xmlString);
        InputSource inputSource = new InputSource(stringReader);
        parser.parse(inputSource);
where xmlSting is the string containing the test.xml.

We want to use local file system such as c:/temp instead of http url.  But we don't want to use the absolute path.  How does it work?

Thanks
Philip

Reply via email to