aboutsummaryrefslogtreecommitdiff
path: root/libxsd
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2014-04-10 12:57:06 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2014-04-10 12:57:06 +0200
commit884dea7531962b17ef843ac2175faa050e8b0758 (patch)
treed70950ab2a6f314b06f37faa67252678ce3007b1 /libxsd
parent0f6ff689dc6bae8fed94da0fcabd39f015e7a62b (diff)
Add support for ordered types, mixed content
Diffstat (limited to 'libxsd')
-rw-r--r--libxsd/xsd/cxx/tree/elements.hxx40
-rw-r--r--libxsd/xsd/cxx/tree/elements.ixx21
-rw-r--r--libxsd/xsd/cxx/xml/dom/parsing-source.hxx33
-rw-r--r--libxsd/xsd/cxx/xml/dom/parsing-source.txx44
4 files changed, 118 insertions, 20 deletions
diff --git a/libxsd/xsd/cxx/tree/elements.hxx b/libxsd/xsd/cxx/tree/elements.hxx
index 6270c40..89be61e 100644
--- a/libxsd/xsd/cxx/tree/elements.hxx
+++ b/libxsd/xsd/cxx/tree/elements.hxx
@@ -21,6 +21,7 @@
#include <map>
#include <string>
#include <memory> // std::auto_ptr/unique_ptr
+#include <cstddef> // std::size_t
#include <istream>
#include <sstream>
#include <cassert>
@@ -190,7 +191,6 @@ namespace xsd
unsigned long x_;
};
-
// Parsing properties. Refer to xsd/cxx/xml/elements.hxx for XML-
// related properties.
//
@@ -199,6 +199,44 @@ namespace xsd
{
};
+ /**
+ * @brief Content order sequence entry.
+ *
+ * @nosubgrouping
+ */
+ struct content_order
+ {
+ /**
+ * @brief Initialize an instance with passed id and index.
+ *
+ * @param id Content id.
+ * @param index Content index in the corresponding sequence.
+ */
+ content_order (std::size_t id, std::size_t index = 0)
+ : id (id), index (index)
+ {
+ }
+
+ /**
+ * @brief Content id.
+ */
+ std::size_t id;
+
+ /**
+ * @brief Content index.
+ */
+ std::size_t index;
+ };
+
+ bool
+ operator== (const content_order&, const content_order&);
+
+ bool
+ operator!= (const content_order&, const content_order&);
+
+ bool
+ operator< (const content_order&, const content_order&);
+
//@cond
// DOM user data keys.
diff --git a/libxsd/xsd/cxx/tree/elements.ixx b/libxsd/xsd/cxx/tree/elements.ixx
index 1098299..da8a83e 100644
--- a/libxsd/xsd/cxx/tree/elements.ixx
+++ b/libxsd/xsd/cxx/tree/elements.ixx
@@ -8,6 +8,27 @@ namespace xsd
{
namespace tree
{
+ // content_order_type
+ //
+
+ inline bool
+ operator== (const content_order& x, const content_order& y)
+ {
+ return x.id == y.id && x.index == y.index;
+ }
+
+ inline bool
+ operator!= (const content_order& x, const content_order& y)
+ {
+ return !(x == y);
+ }
+
+ inline bool
+ operator< (const content_order& x, const content_order& y)
+ {
+ return x.id < y.id || (x.id == y.id && x.index < y.index);
+ }
+
// type
//
diff --git a/libxsd/xsd/cxx/xml/dom/parsing-source.hxx b/libxsd/xsd/cxx/xml/dom/parsing-source.hxx
index 1c53928..fac1006 100644
--- a/libxsd/xsd/cxx/xml/dom/parsing-source.hxx
+++ b/libxsd/xsd/cxx/xml/dom/parsing-source.hxx
@@ -30,30 +30,47 @@ namespace xsd
{
namespace dom
{
- // Parser state object. Can be used for parsing element, attributes,
- // or both.
+ // Parser state object. Can be used for parsing elements (and
+ // optionally text), attributes, or both.
//
template <typename C>
class parser
{
public:
- parser (const xercesc::DOMElement& e, bool ep, bool ap);
+ parser (const xercesc::DOMElement& e, bool ep, bool tp, bool ap);
+ // Content parsing.
+ //
bool
- more_elements ()
+ more_content ()
{
- return next_element_ != 0;
+ return next_content_ != 0;
}
const xercesc::DOMElement&
cur_element ()
{
- return *static_cast<const xercesc::DOMElement*> (next_element_);
+ return *static_cast<const xercesc::DOMElement*> (next_content_);
+ }
+
+ const xercesc::DOMText&
+ cur_text ()
+ {
+ return *static_cast<const xercesc::DOMText*> (next_content_);
+ }
+
+ bool
+ cur_is_text ()
+ {
+ return next_content_->getNodeType () !=
+ xercesc::DOMNode::ELEMENT_NODE;
}
void
- next_element ();
+ next_content (bool text);
+ // Attribute parsing.
+ //
bool
more_attributes ()
{
@@ -86,7 +103,7 @@ namespace xsd
private:
const xercesc::DOMElement& element_;
- const xercesc::DOMNode* next_element_;
+ const xercesc::DOMNode* next_content_;
const xercesc::DOMNamedNodeMap* a_;
XMLSize_t ai_; // Index of the next DOMAttr.
diff --git a/libxsd/xsd/cxx/xml/dom/parsing-source.txx b/libxsd/xsd/cxx/xml/dom/parsing-source.txx
index 8eb4d6e..c789fa6 100644
--- a/libxsd/xsd/cxx/xml/dom/parsing-source.txx
+++ b/libxsd/xsd/cxx/xml/dom/parsing-source.txx
@@ -29,9 +29,9 @@ namespace xsd
//
template <typename C>
parser<C>::
- parser (const xercesc::DOMElement& e, bool ep, bool ap)
+ parser (const xercesc::DOMElement& e, bool ep, bool tp, bool ap)
: element_ (e),
- next_element_ (0),
+ next_content_ (0),
a_ (0),
ai_ (0)
{
@@ -39,10 +39,21 @@ namespace xsd
if (ep)
{
- for (next_element_ = e.getFirstChild ();
- next_element_ != 0 &&
- next_element_->getNodeType () != DOMNode::ELEMENT_NODE;
- next_element_ = next_element_->getNextSibling ()) /*noop*/;
+ for (next_content_ = e.getFirstChild ();;
+ next_content_ = next_content_->getNextSibling ())
+ {
+ if (next_content_ == 0)
+ break;
+
+ DOMNode::NodeType t (next_content_->getNodeType ());
+
+ if (t == DOMNode::ELEMENT_NODE)
+ break;
+
+ if (tp && (t == DOMNode::TEXT_NODE ||
+ t == DOMNode::CDATA_SECTION_NODE))
+ break;
+ }
}
if (ap)
@@ -54,14 +65,25 @@ namespace xsd
template <typename C>
void parser<C>::
- next_element ()
+ next_content (bool tp)
{
using xercesc::DOMNode;
- for (next_element_ = next_element_->getNextSibling ();
- next_element_ != 0 &&
- next_element_->getNodeType () != DOMNode::ELEMENT_NODE;
- next_element_ = next_element_->getNextSibling ())/*noop*/;
+ for (next_content_ = next_content_->getNextSibling ();;
+ next_content_ = next_content_->getNextSibling ())
+ {
+ if (next_content_ == 0)
+ break;
+
+ DOMNode::NodeType t (next_content_->getNodeType ());
+
+ if (t == DOMNode::ELEMENT_NODE)
+ break;
+
+ if (tp && (t == DOMNode::TEXT_NODE ||
+ t == DOMNode::CDATA_SECTION_NODE))
+ break;
+ }
}
// parse()