From f0e0fb5f3f2af8b695680e84572137660ffd835b Mon Sep 17 00:00:00 2001
From: Karen Arutyunov In this chapter we will examine how to parse a very simple XML
document using the XSD-generated C++/Parser skeletons.
The code presented in this chapter is based on the examples/cxx/parser/
directory in the XSD
- distribution contains a collection of examples and a README
- file with an overview of each example.cxx/parser/
directory in the
+ xsd-examples package
+ contains a collection of examples and a README file with an overview
+ of each example.README
file in the XSD distribution explains
- how to compile the examples on various platforms.README
file in the
+ xsd-examples package
+ explains how to build the examples.hello
- example which can be found in the examples/cxx/parser/
- directory of the XSD distribution.cxx/parser/
directory in
+ the xsd-examples
+ package.
-$ xsd cxx-parser --xml-parser expat hello.xsd +$ xsd cxx-parser --std c++11 --xml-parser expat hello.xsd
The --xml-parser
option indicates that we want to
@@ -754,8 +757,8 @@ main (int argc, char* argv[])
on these options refer to the
XSD
Compiler Command Line Manual. The 'generated'
example
- in the XSD distribution shows the sample implementation generation
- feature in action.
-$ c++ -I.../libxsd -c driver.cxx hello-pskel.cxx -$ c++ -o driver driver.o hello-pskel.o -lexpat +$ c++ -std=c++11 -I.../libxsd -c driver.cxx hello-pskel.cxx +$ c++ -std=c++11 -o driver driver.o hello-pskel.o -lexpat $ ./driver hello.xml Hello, sun! Hello, moon! @@ -776,9 +779,10 @@ Hello, world!
Here .../libxsd
represents the path to the
- libxsd
directory in the XSD distribution.
- We can also test the error handling. To test XML well-formedness
- checking, we can try to parse hello-pskel.hxx
:
hello-pskel.hxx
:
$ ./driver hello-pskel.hxx @@ -1490,7 +1494,7 @@ gender ::gender ::gender; option to let the XSD compiler know about our type map:-$ xsd cxx-parser --type-map people.map people.xsd +$ xsd cxx-parser --std c++11 --type-map people.map people.xsdIf we now look at the generated
@@ -1738,7 +1742,8 @@ people ::people; recompile our schema and move on to implementing the parsers:people-pskel.hxx
, @@ -1618,9 +1622,9 @@ namespace http://www.example.com/xmlns/mystd::wstring
depending on the character type selected (see Section 5.2, "Character Type and Encoding" for more information). The binary XML Schema - types are mapped to eitherstd::auto_ptr<xml_schema::buffer>
- orstd::unique_ptr<xml_schema::buffer>
- depending on the C++ standard selected (C++98 or C++11, + types are mapped to eitherstd::unique_ptr<xml_schema::buffer>
+ orstd::auto_ptr<xml_schema::buffer>
+ depending on the C++ standard selected (C++11 or C++98, respectively; refer to the--std
XSD compiler command line option for details).-$ xsd cxx-parser --xml-parser expat --type-map people.map people.xsd +$ xsd cxx-parser --std c++11 --xml-parser expat --type-map people.map \ + people.xsdHere is the implementation of our three parsers in full. One @@ -1882,8 +1887,8 @@ main (int argc, char* argv[])
-$ c++ -I.../libxsd -c driver.cxx people-pskel.cxx -$ c++ -o driver driver.o people-pskel.o -lexpat +$ c++ -std=c++11 -I.../libxsd -c driver.cxx people-pskel.cxx +$ c++ -std=c++11 -o driver driver.o people-pskel.o -lexpat $ ./driver people.xml first: John last: Doe @@ -1917,12 +1922,12 @@ age: 285.1 C++ Standard
-The C++/Parser mapping provides support for ISO/IEC C++ 1998/2003 (C++98) - and ISO/IEC C++ 2011 (C++11). To select the C++ standard for the +
The C++/Parser mapping provides support for ISO/IEC C++ 2011 (C++11) + and ISO/IEC C++ 1998/2003 (C++98). To select the C++ standard for the generated code we use the
+ C++11, the document explains the C++11/98 usage difference and so + they can easily be converted to C++98.--std
XSD compiler command line option. While the majority of the examples in this guide use - C++98, support for the new functionality and library components - introduced in C++11 are discussed throughout the document.5.2 Character Type and Encoding
@@ -2354,9 +2359,10 @@ private:Most of code presented in this section is taken from the
@@ -2754,8 +2760,8 @@ namespace xml_schemapolymorphism
example which can be found in the -examples/cxx/parser/
directory of the XSD distribution. - Handling ofxsi:type
and substitution groups when used - on root elements requires a number of special actions as shown in +cxx/parser/
directory in the + xsd-examples package. + Handling ofxsi:type
and substitution groups when used on + root elements requires a number of special actions as shown in thepolyroot
example.The return type of the
-- cgit v1.1base64_binary_pimpl
andhex_binary_pimpl
parser implementations is either -std::auto_ptr<xml_schema::buffer>
(C++98) or -std::unique_ptr<xml_schema::buffer>
(C++11), +std::unique_ptr<xml_schema::buffer>
(C++11) or +std::auto_ptr<xml_schema::buffer>
(C++98), depending on the C++ standard selected (--std
XSD compiler option). Thexml_schema::buffer
type represents a binary buffer and its interface is presented below.