[xsd-users] Q: schemaLocation in schema file

Rangarajan, Ravi_Sowmian raviraja at qti.qualcomm.com
Wed Feb 12 15:09:18 EST 2014


Hi Boris,

Firstly, thanks so much for digging deep in order to help resolve my issue. I do pass options/arguments as per snippet below. ContentFile (arg[1] in your example?) is the XML instance that we want to parse against the schema MPD.xsd. Earler, with just don't_initialize directive, we got the same error as you (library.xml:13:65 error: schemaLocation does not contain namespace location pairs) even though we were overriding schemaLocation as shown below. After adding don't_validate in addition to don't_initialize, now parser doesn't throw exception and is able to proceed. I do think doing validation is a good thing, but for an optional param like schemaLocation per 3GPP spec, skipping validation shouldn't be too bad?



Thanks

Ravi



    const std::string MPD_NAMESPACE_STRING = "urn:mpeg:dash:schema:mpd:2011";

    const std::string MPD_SCHEMA_FILE      = "/opt/lte/etc/xsd/MPD.xsd";

    const std::string MPD_SCHEMA_URI      = "file://" + MPD_SCHEMA_FILE;



    xml_schema::properties schemaProperties;

    schemaProperties.schema_location(MPD_NAMESPACE_STRING, MPD_SCHEMA_URI);



    std::auto_ptr<mpd_2011::MPDtype> myMPD;

    xml_schema::namespace_infomap map;



    try

    {

        std::auto_ptr<mpd_2011::MPDtype> myMPD

        (

                mpd_2011::MPD(contentFile,

                xml_schema::flags::dont_initialize | xml_schema::flags::dont_validate,

                schemaProperties

        ));

    }

  catch

   {

   }

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Tuesday, February 11, 2014 8:47 PM
To: Rangarajan, Ravi_Sowmian
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Q: schemaLocation in schema file



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:///<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<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