[xsd-users] Re: Questions & Propositions for CodeSynthesis XSD
developer(s)
Boris Kolpackov
boris at codesynthesis.com
Fri Jun 26 01:03:57 EDT 2009
Hi,
In the future please send questions about CodeSynthesis XSD to the
xsd-users at codesynthesis.com mailing list instead of to me directly.
See the posting guidelines for more information:
http://www.codesynthesis.com/support/posting-guidelines.xhtml
zanneo <zanneo at mail.ru> writes:
> I have some questions and propositions for CodeSynthesis XSD developer(s):
> 1. Can further XSD version generate C++ classes that use some abstract
> interface for parser. For example, now classes and templates use strict
> binding to Xerces C++.
We considered this idea but decided against implementing something
like this because the C++/Tree API is "integrated" with the underlying
DOM API in several areas, namely:
- wildcard content (xs:any/xs:anyAttribute)
- DOM node association / XPath processing
- object model customization
Supporting this properly would require providing a fairly complete
wrapping of the native DOM API which would add a significant amount
of code and slow things down. So we decided to go for simplicity
rather than flexibility in this area.
Plus, the C++/Tree mapping relies on the XML Schema validation in
the underlying XML parser and there are no other open-source parsers
that have working (let alone mature) XML Schema support other than
Xerces-C++.
> I want to use TinyXml parser for DOM.
Note that TinyXML is not a conforming XML 1.0 parser. It can only parse
a subset of valid XML documents. See this blog post for details:
http://www.codesynthesis.com/~boris/blog/2008/05/19/real-xml-parser/
If size is the reason for you wanting to use TinyXML instead of
Xerces-C++ then you may want to consider XSD/e and its C++/Hybrid
mapping:
http://www.codesynthesis.com/products/xsde/
You will get an API similar to C++/Tree with a much smaller footprint,
even smaller than if you were using C++/Tree with TinyXML instead of
Xerces-C++.
> 2. I don't understand, how I can use generated classes that interpret
> enumeration from XML Schema. Some generated class has two static arrays:
> first with values, second - with names. But I've drawn attention that
> values by indexes from one array don't match with values by even(!)
> indexes from other array.
String-based enumerations in C++/Tree are mapped to C++ classes that
provides a dual interface: that of the base type (e.g., string or
token) and of the type that behaves similar to a C++ enum. See
Section 2.6.4, "Mapping for Enumerations" in the C++/Tree Mapping
User Manual:
http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.6.2
In particular, if you have the following enumeration defined in
schema:
<simpleType name="color">
<restriction base="string">
<enumeration value="red"/>
<enumeration value="green"/>
<enumeration value="blue"/>
</restriction>
</simpleType>
Then you can get the enum value as a string:
color c = ...
std::string& sc = c;
Or as a C++ enum value:
color c = ...
color::value ec = c;
switch (ec)
{
case color::red:
{
...
}
case color::green:
{
...
}
}
The arrays that you see are internal implementation details.
Boris
More information about the xsd-users
mailing list