[xsd-users] Writing CityGML ADE

Olivier Tournaire olitour at gmail.com
Fri Nov 13 04:34:22 EST 2015


Boris,

Thanks for you quick reply. I tried to use the same implementation as
NIST-ITL for custom schema, but still have the same problem. I attach the
implementation I use. Hope you can give me some ideas to fix this problem!

Best regards

Olivier

2015-11-12 16:16 GMT+01:00 Boris Kolpackov <boris at codesynthesis.com>:

> Hi Olivier,
>
> Olivier Tournaire <olitour at gmail.com> writes:
>
> > As you can see, the namespace is correct, but the name of the property is
> > always the same. It seems that it is always the last one defined in the
> > ADE.
>
> If more than one element substitutes for the same type, XSD can pick any
> one of them since the result will be valid according to the schema. This
> is a pretty poor (IMO) vocabulary design that uses element names as some
> kind of significant application-specific IDs. This page on the Wiki
> discussed one possible solution:
>
> http://wiki.codesynthesis.com/Schemas/NIST-ITL
>
> Boris
>
-------------- next part --------------
// Copyright (C) 2005-2010 Code Synthesis Tools CC
//
// This program was generated by CodeSynthesis XSD, an XML Schema to
// C++ data binding compiler.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
// In addition, as a special exception, Code Synthesis Tools CC gives
// permission to link this program with the Xerces-C++ library (or with
// modified versions of Xerces-C++ that use the same license as Xerces-C++),
// and distribute linked combinations including the two. You must obey
// the GNU General Public License version 2 in all respects for all of
// the code used other than Xerces-C++. If you modify this copy of the
// program, you may extend this exception to your version of the program,
// but you are not obligated to do so. If you do not wish to do so, delete
// this exception statement from your version.
//
// Furthermore, Code Synthesis Tools CC makes a special exception for
// the Free/Libre and Open Source Software (FLOSS) which is described
// in the accompanying FLOSSE file.
//

#ifndef XML_SCHEMA_HXX
#define XML_SCHEMA_HXX

// Begin prologue.
//

#include "xs_export.hpp"

//
// End prologue.

#include <xsd/cxx/config.hxx>

#if (XSD_INT_VERSION != 3030000L)
#error XSD runtime version mismatch
#endif

#include <xsd/cxx/pre.hxx>

#ifndef XSD_USE_CHAR
#define XSD_USE_CHAR
#endif

#ifndef XSD_CXX_TREE_USE_CHAR
#define XSD_CXX_TREE_USE_CHAR
#endif

#include <xsd/cxx/xml/char-utf8.hxx>

#include <xsd/cxx/tree/exceptions.hxx>
#include <xsd/cxx/tree/elements.hxx>
#include <xsd/cxx/tree/types.hxx>

#include <xsd/cxx/xml/error-handler.hxx>

#include <xsd/cxx/xml/dom/auto-ptr.hxx>

#include <xsd/cxx/tree/parsing.hxx>
#include <xsd/cxx/tree/parsing/byte.hxx>
#include <xsd/cxx/tree/parsing/unsigned-byte.hxx>
#include <xsd/cxx/tree/parsing/short.hxx>
#include <xsd/cxx/tree/parsing/unsigned-short.hxx>
#include <xsd/cxx/tree/parsing/int.hxx>
#include <xsd/cxx/tree/parsing/unsigned-int.hxx>
#include <xsd/cxx/tree/parsing/long.hxx>
#include <xsd/cxx/tree/parsing/unsigned-long.hxx>
#include <xsd/cxx/tree/parsing/boolean.hxx>
#include <xsd/cxx/tree/parsing/float.hxx>
#include <xsd/cxx/tree/parsing/double.hxx>
#include <xsd/cxx/tree/parsing/decimal.hxx>

#include <xsd/cxx/xml/dom/serialization-header.hxx>
#include <xsd/cxx/tree/serialization.hxx>
#include <xsd/cxx/tree/serialization/byte.hxx>
#include <xsd/cxx/tree/serialization/unsigned-byte.hxx>
#include <xsd/cxx/tree/serialization/short.hxx>
#include <xsd/cxx/tree/serialization/unsigned-short.hxx>
#include <xsd/cxx/tree/serialization/int.hxx>
#include <xsd/cxx/tree/serialization/unsigned-int.hxx>
#include <xsd/cxx/tree/serialization/long.hxx>
#include <xsd/cxx/tree/serialization/unsigned-long.hxx>
#include <xsd/cxx/tree/serialization/boolean.hxx>
#include <xsd/cxx/tree/serialization/float.hxx>
#include <xsd/cxx/tree/serialization/double.hxx>
#include <xsd/cxx/tree/serialization/decimal.hxx>

namespace xml_schema
{
  // anyType and anySimpleType.
  //
  typedef ::xsd::cxx::tree::type type_base;
  class type;
  typedef ::xsd::cxx::tree::simple_type< type > simple_type;
  typedef ::xsd::cxx::tree::type container;

  // 8-bit
  //
  typedef signed char byte;
  typedef unsigned char unsigned_byte;

  // 16-bit
  //
  typedef short short_;
  typedef unsigned short unsigned_short;

  // 32-bit
  //
  typedef int int_;
  typedef unsigned int unsigned_int;

  // 64-bit
  //
  typedef long long long_;
  typedef unsigned long long unsigned_long;

  // Supposed to be arbitrary-length integral types.
  //
  typedef long long integer;
  typedef long long non_positive_integer;
  typedef unsigned long long non_negative_integer;
  typedef unsigned long long positive_integer;
  typedef long long negative_integer;

  // Boolean.
  //
  typedef bool boolean;

  // Floating-point types.
  //
  typedef float float_;
  typedef double double_;
  typedef double decimal;

  // String types.
  //
  typedef ::xsd::cxx::tree::string< char, simple_type > string;
  typedef ::xsd::cxx::tree::normalized_string< char, string > normalized_string;
  typedef ::xsd::cxx::tree::token< char, normalized_string > token;
  typedef ::xsd::cxx::tree::name< char, token > name;
  typedef ::xsd::cxx::tree::nmtoken< char, token > nmtoken;
  typedef ::xsd::cxx::tree::nmtokens< char, simple_type, nmtoken > nmtokens;
  typedef ::xsd::cxx::tree::ncname< char, name > ncname;
  typedef ::xsd::cxx::tree::language< char, token > language;

  // ID/IDREF.
  //
  typedef ::xsd::cxx::tree::id< char, ncname > id;
  typedef ::xsd::cxx::tree::idref< char, ncname, type > idref;
  typedef ::xsd::cxx::tree::idrefs< char, simple_type, idref > idrefs;

  // URI.
  //
  typedef ::xsd::cxx::tree::uri< char, simple_type > uri;

  // Qualified name.
  //
  typedef ::xsd::cxx::tree::qname< char, simple_type, uri, ncname > qname;

  // Binary.
  //
  typedef ::xsd::cxx::tree::buffer< char > buffer;
  typedef ::xsd::cxx::tree::base64_binary< char, simple_type > base64_binary;
  typedef ::xsd::cxx::tree::hex_binary< char, simple_type > hex_binary;

  // Date/time.
  //
  typedef ::xsd::cxx::tree::time_zone time_zone;
  typedef ::xsd::cxx::tree::date< char, simple_type > date;
  typedef ::xsd::cxx::tree::date_time< char, simple_type > date_time;
  typedef ::xsd::cxx::tree::duration< char, simple_type > duration;
  typedef ::xsd::cxx::tree::gday< char, simple_type > gday;
  typedef ::xsd::cxx::tree::gmonth< char, simple_type > gmonth;
  typedef ::xsd::cxx::tree::gmonth_day< char, simple_type > gmonth_day;
  typedef ::xsd::cxx::tree::gyear< char, simple_type > gyear;
  typedef ::xsd::cxx::tree::gyear_month< char, simple_type > gyear_month;
  typedef ::xsd::cxx::tree::time< char, simple_type > time;

  // Entity.
  //
  typedef ::xsd::cxx::tree::entity< char, ncname > entity;
  typedef ::xsd::cxx::tree::entities< char, simple_type, entity > entities;

  // Namespace information and list stream. Used in
  // serialization functions.
  //
  typedef ::xsd::cxx::xml::dom::namespace_info< char > namespace_info;
  typedef ::xsd::cxx::xml::dom::namespace_infomap< char > namespace_infomap;
  typedef ::xsd::cxx::tree::list_stream< char > list_stream;
  typedef ::xsd::cxx::tree::as_double< double_ > as_double;
  typedef ::xsd::cxx::tree::as_decimal< decimal > as_decimal;
  typedef ::xsd::cxx::tree::facet facet;

  // Flags and properties.
  //
  typedef ::xsd::cxx::tree::flags flags;
  typedef ::xsd::cxx::tree::properties< char > properties;

  // Parsing/serialization diagnostics.
  //
  typedef ::xsd::cxx::tree::severity severity;
  typedef ::xsd::cxx::tree::error< char > error;
  typedef ::xsd::cxx::tree::diagnostics< char > diagnostics;

  // Exceptions.
  //
  typedef ::xsd::cxx::tree::exception< char > exception;
  typedef ::xsd::cxx::tree::bounds< char > bounds;
  typedef ::xsd::cxx::tree::duplicate_id< char > duplicate_id;
  typedef ::xsd::cxx::tree::parsing< char > parsing;
  typedef ::xsd::cxx::tree::expected_element< char > expected_element;
  typedef ::xsd::cxx::tree::unexpected_element< char > unexpected_element;
  typedef ::xsd::cxx::tree::expected_attribute< char > expected_attribute;
  typedef ::xsd::cxx::tree::unexpected_enumerator< char > unexpected_enumerator;
  typedef ::xsd::cxx::tree::expected_text_content< char > expected_text_content;
  typedef ::xsd::cxx::tree::no_prefix_mapping< char > no_prefix_mapping;
  typedef ::xsd::cxx::tree::no_type_info< char > no_type_info;
  typedef ::xsd::cxx::tree::not_derived< char > not_derived;
  typedef ::xsd::cxx::tree::serialization< char > serialization;

  // Error handler callback interface.
  //
  typedef ::xsd::cxx::xml::error_handler< char > error_handler;

  // DOM interaction.
  //
  namespace dom
  {
    // Automatic pointer for DOMDocument.
    //
    using ::xsd::cxx::xml::dom::auto_ptr;

    // DOM user data key for back pointers to tree nodes.
    //
    const XMLCh* const tree_node_key = ::xsd::cxx::tree::user_data_keys::node;
  }
}

#include <xsd/cxx/post.hxx>

// Begin epilogue.
//
#include "xml-schema-custom.hxx"
//
// End epilogue.

#endif // XML_SCHEMA_HXX
-------------- next part --------------
#include <cassert>

// Include xml-schema.hxx instead of xml-schema-custom.hxx here.
//
#include "xml-schema.hxx"

#include <xercesc/dom/DOMComment.hpp>
#include <xercesc/dom/DOMDocument.hpp>

#include <xsd/cxx/xml/string.hxx> // xml::transcode, xml::string

namespace xml = xsd::cxx::xml;

namespace xml_schema
{
  type::
  type ()
      : type_base ()
  {
  }

  type::
  type (const xercesc::DOMElement& e, flags f, container* c)
      : type_base (e, f, c)
  {
    // Extract element name and use it as the type id.
    //
    type_id_ = xml::transcode<char> (e.getNodeName ());

    name_ = xml::transcode<char> (e.getLocalName ());

    if (const XMLCh* ns = e.getNamespaceURI ())
        namespace_ = xml::transcode<char> (ns);
  }

  type::
  type (const xercesc::DOMAttr& a, flags f, container* c)
      : type_base (a, f, c)
  {
    // No substitution groups in attributes.
    //
  }

  type::
  type (const std::string& s, const xercesc::DOMElement* e,
        flags f, container* c)
      : type_base (s, e, f, c)
  {
    // No substitution groups in list items.
    //
  }

  type::
  type (const type& x, flags f, container* c)
      : type_base (x, f, c), type_id_ (x.type_id_), name_ (x.name_), namespace_ (x.namespace_)
  {
  }

  type* type::
  _clone (flags f, container* c) const
  {
    return new type (*this, f, c);
  }

  // Serialization operators.
  //
  void
  operator<< (xercesc::DOMElement& e, const type& x)
  {
    using namespace std;
    using namespace xercesc;

    // Change element name if it doesn't match type id.
    //
    const string& tid (x._type_id ());
    const string& n (x._name ());
    const string& ns (x._namespace ());

    std::string sdlfkjsdfklj = xml::transcode<char> (e.getNodeName ());

    if (!tid.empty () && xml::transcode<char> (e.getNodeName ()) != tid)
    {
      DOMDocument* doc = e.getOwnerDocument ();


      const XMLCh* ns;
      string::size_type p (tid.find (':'));

      if (p != string::npos)
      {
        string prefix (tid, 0, p);
        ns = e.lookupNamespaceURI (xml::string (prefix).c_str ());
      }
      else
        ns = e.lookupNamespaceURI (0);

      DOMNode* n = doc->renameNode (&e, ns, xml::string (tid).c_str ());
      assert (n == &e);
    }

    // Call our base.
    //
    const type_base& b (x);
    e << b;
  }
}
-------------- next part --------------
// Do not include this file directly, use xml-schema.hxx instead. This
// file is included into generated xml-schema.hxx so we do not need to
// guard against multiple inclusions.
//

#include <string>

namespace xml_schema
{
  class XS_EXPORT type: public type_base
  {
  public:
    type ();
    type (const xercesc::DOMElement&, flags = 0, container* = 0);
    type (const xercesc::DOMAttr&, flags = 0, container* = 0);
    type (const std::string&, const xercesc::DOMElement*,
          flags = 0, container* = 0);
    type (const type&, flags = 0, container* = 0);

    virtual type*
    _clone (flags = 0, container* = 0) const;

  public:
    // Type id.
    //
    const std::string& _type_id () const
    {
      return type_id_;
    }

    void _type_id (const std::string& id)
    {
      type_id_ = id;
    }

    void
        _name (const std::string& n)
    {
        name_ = n;
    }

    void _namespace (const std::string& ns)
    {
        namespace_ = ns;
    }

    const std::string& _name () const
    {
        return name_;
    }

    const std::string& _namespace () const
    {
        return namespace_;
    }

  private:
    std::string type_id_;
    std::string name_;
    std::string namespace_;
  };

  // New element serialization operator.
  //
  void
  operator<< (xercesc::DOMElement&, const type&);
}


More information about the xsd-users mailing list