[xsd-users] Q: schemaLocation in schema file

Rangarajan, Ravi_Sowmian raviraja at qti.qualcomm.com
Mon Feb 10 14:33:15 EST 2014


Hi Boris,

Sorry for not being clear the first time. We do specify/pass name/location of schema to code synthesis parser via the code snippet below. What I was asking is that code synthesis throws an exception (and fails parsing) if an XML instance file doesn't contain namespace as well as location components in schemaLocation field (as shown in green below). I tried to remove schemaLocation field from my schema file or just specify namespace (missing out the location part) as in red below - I cannot even compile the XSD files without the entry as in green below.



My question was how do I tell code synthesis to ignore if schemaLocation field is completely missing from XML instance file or it could be present, but location part could be missing? (I mean any way other than telling code synthesis not to validate schema).

Thank you

Ravi



Way I pass schema_location to code synthesis:

=======================================

xml_schema::properties schemaProperties;

schemaProperties.schema_location(...)



what is in my schema (first few lines):

=================================

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="urn:mpeg:DASH:schema:MPD:2011" targetNamespace="urn:mpeg:DASH:schema:MPD:2011" elementFormDefault="qualified" attributeFormDefault="unqualified">

        <xs:import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink.xsd"/>



xlink.xsd and xml.xsd which it in turn imports are present in the same directory.



What keeps code synthesis happy:

=============================

<?xml version="1.0" encoding="UTF-8"?>

<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xmlns="urn:mpeg:dash:schema:mpd:2011"

  xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011 MPD.xsd"



What results in code synthesis throwing exception and fails parsing:

=========================================================

<?xml version="1.0" encoding="UTF-8"?>

<MPD xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xmlns="urn:mpeg:dash:schema:mpd:2011"

  xsi:schemaLocation="urn:mpeg:dash:schema:mpd:2011"



I want code synthesis to allow schemaLocation completely missing from XML instance file or just the namespace field can be present.





-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Sunday, February 09, 2014 2:13 AM
To: Rangarajan, Ravi_Sowmian
Cc: xsd-users at codesynthesis.com
Subject: Re: [xsd-users] Q: schemaLocation in schema file



Hi Ravi,



Rangarajan, Ravi_Sowmian <raviraja at qti.qualcomm.com<mailto:raviraja at qti.qualcomm.com>> writes:



> Currently, my schema is looking for a namespace component and a

> location component in schemaLocation attribute. If location field is

> missing, code synthesis throws an exception. Since location and/or

> namespace fields in schemaLocation are optional, then I am wondering

> what would be the best way to specify schemaLocation in the schema

> template such that code synthesis parser would handle the three scenarios below properly?



Generally, it is not a good idea to rely on the schemaLocation attribute in production applications. It is better to ignore it and specify the location/schema from within the application. For more information on various ways to achieve this, refer to Section 5.1, "XML Schema Validation and Searching" in the C++/Tree Mapping Getting Started Guide:



http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#5.1



Boris


More information about the xsd-users mailing list