[xsd-users] Q: schemaLocation in schema file

Boris Kolpackov boris at codesynthesis.com
Tue Feb 11 23:46:44 EST 2014


Hi Ravi,

Here is what I did:

1. I took the 'library' example from the XSD distribution and modified
   the library.xml file so that the schemaLocation attribute contains
   library1.xsd instead of library.xsd (file that doesn't exist). I
   then run the example and verified that I get the errors.

2. I then added:
 
   #include <unistd.h> // getcwd

   To the top of driver.cxx and the following code fragment at the
   beginning of main() (just after using namespace library;):

    char cwd[1024];
    getcwd (cwd, 1024);

    xml_schema::properties props;

    props.schema_location (
      "http://www.codesynthesis.com/library",
      "file:///" + std::string (cwd) + "/library.xsd");

    cerr << "schema location: " << props.schema_location () << endl;

   I also changed the parsing function call that reads like this:

   std::auto_ptr<catalog> c (catalog_ (argv[1]));

   To instead read like this:

   std::auto_ptr<catalog> c (catalog_ (argv[1], 0, props));

   That is, I am passing the properties with the schema location
   to the parsing function (perhaps you forgot to this step)?

3. I then re-built the example and ran it on the modified library.xml.
   The example now runs without any problems and the schema location
   printed, in my case, as:

   schema location: http://www.codesynthesis.com/library file:////home/boris/work/xsd/xsd-default/examples/cxx/tree/test/library.xsd

4. I then modified the schemaLocation attribue to only include the
   namespace, without the schema path. This results in an error that
   says:

   library.xml:13:65 error: schemaLocation does not contain namespace-
   location pairs

   So this is invalid per the XML Schema specification.

Can you try these steps and see if you get the same results? If you
do get the same results, then check what you are doing different in
your code.

Boris



More information about the xsd-users mailing list