[xsd-users] cxx-parser: Not all attributes in the XML namespace are typemapped.

Jeroen N. Witmond [Bahco] jnw at xs4all.nl
Mon Dec 31 11:31:59 EST 2007


Hi Boris,

Boris Kolpackov <boris at codesynthesis.com> writes:
> Jeroen N. Witmond [Bahco] <jnw at xs4all.nl> writes:
>
>> Attributes lang and space are (anonymous) simpleTypes, where base
>> and id are xs:anyUri resp. xs:ID.
>>
>> Is this expected behavior of xsd cxx-parser?
>
> Yes, type maps are mapping types, not attributes or elements. If
> you want the base and id attributes to be represented by your own
> C++ types, then you will need to re-map xs:anyUri and xs:ID (and
> by doing this you will also make other attributes/elements that
> are of these built-in types to use your custom C++ types).

It's not so much that I want to use custom types. What I was trying to
achieve with them was a proper source code organization. I use multiple
xsd files (one importing the other) and I prefer the code generated and
written for each xsd file to have its own distinct set of source files.

I have added a new implementation, parser-datamodel, to my page on
cxx-parser[1, bottom left]. This implementation introduces a data model to
handle the uniquenes of xml:id and the inheritance of the other attributes
in that namespace. In this implementation, which is based on a Schema that
references these attributes explicitely, the setters for xml:base and
xml:id are called from the application's source files.

To the same page[1, bottom right] I added another new implementation,
parser-anytype, that is based on your examples[2] and uses almost the same
data model as parser-datamodel above. The advantages of parser-anytype are
that it does not depend on how the client Schema treats the attributes,
and that the maintenance of the data model is hidden from the application
logic.

All this also resulted in a number of questions and comments:

1. The generated test driver for parser-datamodel contains, under '//
Instantiate individual parsers.', the declaration
'::xml_schema::ncname_pimpl ncname_p;'. This variable ncname_p is never
used.

2. It would be nice if cxx-parser supported the --generate-xml-schema and
--extern-xml-schema like cxx-tree.

3. In the handler for xml:id, I throw an exception when the value of the
attribute has been seen before. Is there a way to include information
about the source location in the xml file in this exception?

I also reworked the data model into a new implementation,
custom-datamodel, for my page on cxx-tree[3, item 7]. custom-datamodel is
based on custom-intended [3, item 4], and like it uses a customization of
anyType.

In custom-datamodel, the code for the data model and its interaction with
the code generated by xsd cxx-tree can be used both with char and with
wchar_t as the character type for the application logic.

Note that for custom-datamodel, I use cxx-parser to generate a program
that in its turn generates the header file that defines the literals for
both character types. :)

4. To handle the inheritance for an element, I need access to the parent
of that element. At the moment, I use an ugly hack for this, see file
custom-datamodel/XmlNamespace.cpp[4], starting at line 146. Is there a
better way to do this?

5. When I throw an exception in the setter for xml:id (called from the
constructor of the custom type), the program terminates with
   pure virtual method called
   terminate called without an active exception
Debugging with Valgrind[4] shows that the DOMDocument is reset twice.

 Invalid read of size 4
    at 0x804B41C:
xsd::cxx::xml::dom::auto_ptr<xercesc_2_7::DOMDocument>::reset(xercesc_2_7::DOMDocument*)
(auto-ptr.hxx:145)
    by 0x804B456:
xsd::cxx::xml::dom::auto_ptr<xercesc_2_7::DOMDocument>::~auto_ptr()
(auto-ptr.hxx:49)
    by 0x8052E9A: metadox::foo(std::string const&, xsd::cxx::tree::flags,
xsd::cxx::tree::properties<char> const&) (lax.cxx:387)
    by 0x805ACE2: main (driver-char.cpp:87)
  Address 0x51678E4 is 20 bytes inside a block of size 164 free'd
    at 0x401BCBC: operator delete(void*) (vg_replace_malloc.c:244)
    by 0x420ADBC: xercesc_2_7::MemoryManagerImpl::deallocate(void*) (in
/usr/lib/libxerces-c.so.27.0)
    by 0x42D38A8: xercesc_2_7::XMemory::operator delete(void*) (in
/usr/lib/libxerces-c.so.27.0)
    by 0x41889FD: xercesc_2_7::DOMDocumentImpl::~DOMDocumentImpl() (in
/usr/lib/libxerces-c.so.27.0)
    by 0x418542C: xercesc_2_7::DOMDocumentImpl::release() (in
/usr/lib/libxerces-c.so.27.0)
    by 0x804B432:
xsd::cxx::xml::dom::auto_ptr<xercesc_2_7::DOMDocument>::reset(xercesc_2_7::DOMDocument*)
(auto-ptr.hxx:145)
    by 0x804B456:
xsd::cxx::xml::dom::auto_ptr<xercesc_2_7::DOMDocument>::~auto_ptr()
(auto-ptr.hxx:49)
    by 0x804C336:
xsd::cxx::tree::_type::dom_element_info::~dom_element_info()
(elements.hxx:449)
    by 0x804B15E:
std::auto_ptr<xsd::cxx::tree::_type::dom_info>::~auto_ptr()
(memory:259)
    by 0x804CB97: xsd::cxx::tree::_type::~_type() (elements.hxx:190)
    by 0x804CCF5: xml_schema::XmlNamespace<char>::~XmlNamespace()
(XmlNamespace.cpp:281)
    by 0x8051842: metadox::foo_type::foo_type(xercesc_2_7::DOMElement
const&, xsd::cxx::tree::flags, xsd::cxx::tree::_type*) (lax.cxx:254)
    by 0x805A83F: xsd::cxx::tree::traits<metadox::foo_type,
char>::create(xercesc_2_7::DOMElement const&, xsd::cxx::tree::flags,
xsd::cxx::tree::_type*) (elements.hxx:711)
    by 0x80519B7: metadox::foo(xercesc_2_7::DOMDocument*,
xsd::cxx::tree::flags, xsd::cxx::tree::properties<char> const&)
(lax.cxx:648)
    by 0x8052E1D: metadox::foo(std::string const&, xsd::cxx::tree::flags,
xsd::cxx::tree::properties<char> const&) (lax.cxx:382)
    by 0x805ACE2: main (driver-char.cpp:87)

6. As in the case of cxx-parser, it would be nice if I could report the
source location in the xml file also with cxx-tree.

Happy New Year to all!

Jeroen.

[1] http://www.xs4all.nl/~jnw/codesynthesis/xmlnamespace/parser.html
[2] http://codesynthesis.com/pipermail/xsd-users/2007-November/001377.html
[3] http://www.xs4all.nl/~jnw/codesynthesis/xmlnamespace/index.html
[4]
http://www.xs4all.nl/~jnw/codesynthesis/xmlnamespace/custom-datamodel/XmlNamespace.cpp





More information about the xsd-users mailing list