xmlSchemaParse fails to read UNC paths starting with '//' when `xsi:schemaLocation` is relative
I have a similar issue as #387 but with XSD validation, when one schema uses a xsi:schemaLocation
set to a relative path, and everything is on a networked drive.
A fuller explanation along with sample files and a link to a short tutorial about how to create a fake network drive on windows can be found here: https://github.com/NREL/OpenStudio/issues/4791#issuecomment-1419174786
HPXML.xsd
<?xml version='1.0' encoding='UTF-8'?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://hpxmlonline.com/2019/10" targetNamespace="http://hpxmlonline.com/2019/10" elementFormDefault="qualified" version="4.0">
<xs:include schemaLocation="HPXMLBaseElements.xsd"/>
[...]
HPXMLBaseElements.xsd is located next to the HPXML.xsd. Both are on a network drive (which is also local to my machine in fact)
std::string schema_filename_str = "//DESKTOP-AFHNVM1/Users/julien/FakeNetworkSharedDrive/os_validation/HPXML.xsd";
const auto* schema_filename = schema_filename_str.c_str();
std::string xml_filename_str = "//DESKTOP-AFHNVM1/Users/julien/FakeNetworkSharedDrive/os_validation/base.xml";
const auto* xml_filename = xml_filename_str.c_str();
// schema parser ptr
xmlSchemaParserCtxt* parser_ctxt = xmlSchemaNewParserCtxt(schema_filename);
// set parser errors
detail::ErrorCollector schemaParserErrorCollector;
xmlSchemaSetParserErrors(parser_ctxt, detail::callback_messages_error, detail::callback_messages_warning, &schemaParserErrorCollector);
// schema parser
xmlSchema* schema = xmlSchemaParse(parser_ctxt);
xmlCanonicPath
will eat up the leading /
and get super confused.
I have tried a bunch of variations to no avail:
- ` R"(\?//DESKTOP-AFHNVM1/Users/julien/FakeNetworkSharedDrive/os_validation/HPXML.xml)";
R"(\\?\\\DESKTOP-AFHNVM1/Users/julien/FakeNetworkSharedDrive/os_validation/HPXML.xsd")
- Prepending file:// instead
How can I use files that are on a networked drive?
Note that one thing that works is to set the xsi:schemaLocation as an absolute path, but then relocation becomes a pain.
- <xs:include schemaLocation="HPXMLBaseElements.xsd"/>
+ <xs:include schemaLocation="//DESKTOP-AFHNVM1/Users/julien/FakeNetworkSharedDrive/os_validation/HPXMLBaseElements.xsd"/>
Using a mapped letter works too (but afaik, this requires the user to be admin on the machine to map the drive...)