summaryrefslogtreecommitdiff
path: root/xsd-examples/cxx/parser/mixed
diff options
context:
space:
mode:
Diffstat (limited to 'xsd-examples/cxx/parser/mixed')
-rw-r--r--xsd-examples/cxx/parser/mixed/README49
-rw-r--r--xsd-examples/cxx/parser/mixed/anchor.hxx33
-rw-r--r--xsd-examples/cxx/parser/mixed/buildfile25
-rw-r--r--xsd-examples/cxx/parser/mixed/driver.cxx100
-rw-r--r--xsd-examples/cxx/parser/mixed/text.map6
-rw-r--r--xsd-examples/cxx/parser/mixed/text.xml17
-rw-r--r--xsd-examples/cxx/parser/mixed/text.xsd28
7 files changed, 258 insertions, 0 deletions
diff --git a/xsd-examples/cxx/parser/mixed/README b/xsd-examples/cxx/parser/mixed/README
new file mode 100644
index 0000000..23ace6f
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/README
@@ -0,0 +1,49 @@
+This example shows how to handle raw, "type-less content" such as
+mixed content models, anyType/anySimpleType, and any/anyAttribute
+in the C++/Parser mapping.
+
+In this example we use mixed content model to describe text
+with embedded links, e.g.,
+
+ This paragraph talks about <a href="uri">time</a>.
+
+The example transforms such text into plain text with
+references, e.g.,
+
+ This paragraph talks about time[0].
+
+ [0] uri
+
+The example consists of the following files:
+
+text.xsd
+ XML Schema which describes "text with links" instance
+ documents.
+
+text.xml
+ Sample XML instance document.
+
+anchor.hxx
+ Anchor type that captures the information about a link.
+
+text.map
+ Type map. It maps XML Schema anchor types defined in
+ text.xsd to C++ anchor class defined in anchor.hxx.
+
+text-pskel.hxx
+text-pskel.cxx
+ Parser skeletons generated by XSD from text.xsd and
+ text.map.
+
+driver.cxx
+ A parser implementation and a driver for the example. The
+ parser implementation prints the transformed text to STDOUT.
+ The driver first constructs a parser instance from the parser
+ implementation mentioned above and a couple of predefined
+ parsers for the XML Schema built-in types. In then invokes
+ this parser instance to parse the input file.
+
+To run the example on the sample XML instance document simply
+execute:
+
+$ ./driver text.xml
diff --git a/xsd-examples/cxx/parser/mixed/anchor.hxx b/xsd-examples/cxx/parser/mixed/anchor.hxx
new file mode 100644
index 0000000..6cc6cd4
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/anchor.hxx
@@ -0,0 +1,33 @@
+// file : cxx/parser/mixed/anchor.hxx
+// copyright : not copyrighted - public domain
+
+#ifndef ANCHOR_HXX
+#define ANCHOR_HXX
+
+#include <string>
+
+struct anchor
+{
+ anchor (const std::string& text, const std::string& uri)
+ : uri_ (uri), text_ (text)
+ {
+ }
+
+ const std::string&
+ text () const
+ {
+ return text_;
+ }
+
+ const std::string&
+ uri () const
+ {
+ return uri_;
+ }
+
+private:
+ std::string uri_;
+ std::string text_;
+};
+
+#endif // ANCHOR_HXX
diff --git a/xsd-examples/cxx/parser/mixed/buildfile b/xsd-examples/cxx/parser/mixed/buildfile
new file mode 100644
index 0000000..0079444
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/buildfile
@@ -0,0 +1,25 @@
+# file : cxx/parser/mixed/buildfile
+# license : not copyrighted - public domain
+
+import libs = libxsd%lib{xsd}
+import libs += libxerces-c%lib{xerces-c}
+
+./: exe{driver} doc{README}
+
+exe{driver}: {hxx cxx}{* -text-pskel} {hxx ixx cxx}{text-pskel} $libs
+
+exe{driver}: xml{text}: test.input = true
+
+<{hxx ixx cxx}{text-pskel}>: xsd{text} map{text} $xsd
+{{
+ diag xsd ($<[0]) # @@ TMP
+
+ $xsd cxx-parser --std c++11 \
+ --generate-inline \
+ --skel-file-suffix -pskel \
+ --type-map $path($<[1]) \
+ --output-dir $out_base \
+ $path($<[0])
+}}
+
+cxx.poptions =+ "-I$out_base" "-I$src_base"
diff --git a/xsd-examples/cxx/parser/mixed/driver.cxx b/xsd-examples/cxx/parser/mixed/driver.cxx
new file mode 100644
index 0000000..c00bfd7
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/driver.cxx
@@ -0,0 +1,100 @@
+// file : cxx/parser/mixed/driver.cxx
+// copyright : not copyrighted - public domain
+
+#include <string>
+#include <vector>
+#include <iostream>
+
+#include "anchor.hxx"
+#include "text-pskel.hxx"
+
+using namespace std;
+
+struct anchor_pimpl: anchor_pskel, xml_schema::string_pimpl
+{
+ virtual void
+ href (const std::string& uri)
+ {
+ uri_ = uri;
+ }
+
+ virtual anchor
+ post_anchor ()
+ {
+ return anchor (post_string (), uri_);
+ }
+
+private:
+ std::string uri_;
+};
+
+
+struct text_pimpl: text_pskel
+{
+ virtual void
+ a (const anchor& a)
+ {
+ cout << a.text () << "[" << anchors_.size () << "]";
+ anchors_.push_back (a);
+ }
+
+ virtual void
+ _any_characters (const xml_schema::ro_string& s)
+ {
+ cout << s;
+ }
+
+ virtual void
+ post_text ()
+ {
+ for (anchors::const_iterator i (anchors_.begin ());
+ i != anchors_.end ();
+ ++i)
+ {
+ cout << "[" << i - anchors_.begin () << "] " << i->uri () << endl;
+ }
+ }
+
+private:
+ typedef vector<anchor> anchors;
+ anchors anchors_;
+};
+
+
+int
+main (int argc, char* argv[])
+{
+ if (argc != 2)
+ {
+ cerr << "usage: " << argv[0] << " text.xml" << endl;
+ return 1;
+ }
+
+ try
+ {
+ // Construct the parser.
+ //
+ xml_schema::string_pimpl string_p;
+ anchor_pimpl anchor_p;
+ text_pimpl text_p;
+
+ anchor_p.href_parser (string_p);
+ text_p.a_parser (anchor_p);
+
+ xml_schema::document doc_p (text_p, "text");
+
+ text_p.pre ();
+ doc_p.parse (argv[1]);
+ text_p.post_text ();
+ }
+ catch (const xml_schema::exception& e)
+ {
+ cerr << e << endl;
+ return 1;
+ }
+ catch (const std::ios_base::failure&)
+ {
+ cerr << argv[1] << ": unable to open or read failure" << endl;
+ return 1;
+ }
+}
diff --git a/xsd-examples/cxx/parser/mixed/text.map b/xsd-examples/cxx/parser/mixed/text.map
new file mode 100644
index 0000000..0daa79b
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/text.map
@@ -0,0 +1,6 @@
+# file : cxx/parser/mixed/text.map
+# copyright : not copyrighted - public domain
+
+include "anchor.hxx";
+
+anchor ::anchor;
diff --git a/xsd-examples/cxx/parser/mixed/text.xml b/xsd-examples/cxx/parser/mixed/text.xml
new file mode 100644
index 0000000..1ce4eec
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/text.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : cxx/parser/text/text.xml
+copyright : not copyrighted - public domain
+
+-->
+
+<text xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="text.xsd">
+
+The first paragraph of this text talks about <a href="http://en.wikipedia.org/wiki/time">time</a>.
+
+And this paragraph talks about <a href="http://en.wikipedia.org/wiki/space">space</a>.
+
+</text>
diff --git a/xsd-examples/cxx/parser/mixed/text.xsd b/xsd-examples/cxx/parser/mixed/text.xsd
new file mode 100644
index 0000000..e9d6e39
--- /dev/null
+++ b/xsd-examples/cxx/parser/mixed/text.xsd
@@ -0,0 +1,28 @@
+<?xml version="1.0"?>
+
+<!--
+
+file : cxx/parser/mixed/text.xsd
+copyright : not copyrighted - public domain
+
+-->
+
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:complexType name="anchor">
+ <xsd:simpleContent>
+ <xsd:extension base="xsd:string">
+ <xsd:attribute name="href" type="xsd:string" use="required"/>
+ </xsd:extension>
+ </xsd:simpleContent>
+ </xsd:complexType>
+
+ <xsd:complexType name="text" mixed="true">
+ <xsd:sequence>
+ <xsd:element name="a" type="anchor" minOccurs="0" maxOccurs="unbounded"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:element name="text" type="text"/>
+
+</xsd:schema>