[xsd-users] Issue using proxy for Open Packaging Conventions core-properties schema

Rob Ursem Rob.Ursem at cmgl.ca
Fri Jun 21 19:03:33 EDT 2013


This is a rather lengthy piece to clarify the context of my issue.

I'm trying to implement a library for the Open Packaging Conventions files (newer Office file types).
A part of those files is the core properties. This xml file is based on the DublinCore meta data.

The schema for the core properties is:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace=http://schemas.openxmlformats.org/package/2006/metadata/core-properties
xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
elementFormDefault="qualified" blockDefault="#all">

  <xs:import namespace="http://purl.org/dc/elements/1.1/" schemaLocation="http://dublincore.org/schemas/xmls/qdc/2003/04/02/dc.xsd" />
  <xs:import namespace="http://purl.org/dc/terms/" schemaLocation="http://dublincore.org/schemas/xmls/qdc/2003/04/02/dcterms.xsd" />

  <xs:element name="coreProperties" type="CT_CoreProperties" />

  <xs:complexType name="CT_CoreProperties">
    <xs:all>
      <xs:element name="category" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element name="contentStatus" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element name="contentType" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element ref="dcterms:created" minOccurs="0" maxOccurs="1" />
      <xs:element ref="dc:creator" minOccurs="0" maxOccurs="1" />
      <xs:element ref="dc:description" minOccurs="0" maxOccurs="1" />
      <xs:element ref="dc:identifier" minOccurs="0" maxOccurs="1" />
      <xs:element name="keywords" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element ref="dc:language" minOccurs="0" maxOccurs="1" />
      <xs:element name="lastModifiedBy" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element name="lastPrinted" minOccurs="0" maxOccurs="1" type="xs:dateTime" />
      <xs:element ref="dcterms:modified" minOccurs="0" maxOccurs="1" />
      <xs:element name="revision" minOccurs="0" maxOccurs="1" type="xs:string" />
      <xs:element ref="dc:subject" minOccurs="0" maxOccurs="1" />
      <xs:element ref="dc:title" minOccurs="0" maxOccurs="1" />
      <xs:element name="version" minOccurs="0" maxOccurs="1" type="xs:string" />
    </xs:all>
  </xs:complexType>

</xs:schema>

Where 'created' is defined as (dcterms.xsd):
   <xs:element name="created" substitutionGroup="date"/>

My xml test document is:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<coreProperties xmlns="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <dcterms:created xsi:type="dcterms:W3CDTF">2013-06-21T01:47:29Z</dcterms:created>
      <dc:creator>rob</dc:creator>
      <dc:identifier>urn:uuid:079E7602-605A-450B-8C75-E4EE02D6DC33</dc:identifier>
      <version>1.0</version>
</coreProperties>

The complex elements are the ones in the dc and dcterms namespace. For instance W3CDTF is defined in the schema as:
  <xs:complexType name="W3CDTF">
   <xs:simpleContent>
    <xs:restriction base="dc:SimpleLiteral">
        <xs:simpleType>
           <xs:union memberTypes="xs:gYear xs:gYearMonth xs:date xs:dateTime"/>
        </xs:simpleType>
        <xs:attribute ref="xml:lang" use="prohibited"/>
    </xs:restriction>
   </xs:simpleContent>
  </xs:complexType>

And generated as:
  class W3CDTF: public ::dcelms::SimpleLiteral
  {
    public:
    // Constructors.
    //
    W3CDTF ();

    W3CDTF (const ::xml_schema::type&);

    W3CDTF (const ::xercesc::DOMElement& e,
            ::xml_schema::flags f = 0,
            ::xml_schema::container* c = 0);

    W3CDTF (const W3CDTF& x,
            ::xml_schema::flags f = 0,
            ::xml_schema::container* c = 0);

    virtual W3CDTF*
    _clone (::xml_schema::flags f = 0,
            ::xml_schema::container* c = 0) const;

    virtual
    ~W3CDTF ();
  };



A partial of my code is:
1 void CoreProperties::LoadFromPart(EpcInputStream part)
2 {
3     ifstream *is = part.GetStream();
4
 5     dcterms::W3CDTF dummyHackToLoadThisTypeSoParsingDoesntFail;
7
 8     std::auto_ptr<CT_CoreProperties> core = parseCoreProperties(*is, xml_schema::flags::dont_validate);
 9
10    CT_CoreProperties::created_optional created = core->getCreated();
11    if (created.present())
12    {
13        dcterms::W3CDTF p = *created;
14    }

I have (had) two main issues parsing this.


1.       The initialization of types is somehow skipped by the compiler for types that have not been referenced before. If I don't include line 5 above, the "dcterm:W3CDTF type is not registered and my parsing (on line 8) fails. This seems to be an issue with the compiler (VS2012) rather than with XSD.

2.       Once the document is parsed I get a 'created_optional' type (which makes sense). From there on I can get to a dcterms::W3CDTF type (line 13) but I have not been able to get the date value out of that element.

Is there something I'm missing or do I need to do things differently?

Regards,

Rob Ursem



More information about the xsd-users mailing list