summaryrefslogtreecommitdiff
path: root/libxsd/xsd/cxx/xml/dom/parsing-source.hxx
blob: fc0bd71fa7bd73996226749082133865efd11390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// file      : xsd/cxx/xml/dom/parsing-source.hxx
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSD_CXX_XML_DOM_PARSING_SOURCE_HXX
#define XSD_CXX_XML_DOM_PARSING_SOURCE_HXX

#include <string>

#include <xercesc/dom/DOMNode.hpp>
#include <xercesc/dom/DOMAttr.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/DOMNamedNodeMap.hpp>
#include <xercesc/dom/DOMErrorHandler.hpp>

#include <xercesc/sax/InputSource.hpp>

#include <xsd/cxx/xml/elements.hxx>      // properies
#include <xsd/cxx/xml/error-handler.hxx>
#include <xsd/cxx/xml/dom/auto-ptr.hxx>
#include <xsd/cxx/xml/dom/elements.hxx>  // name
#include <xsd/cxx/xml/dom/parsing-header.hxx>

namespace xsd
{
  namespace cxx
  {
    namespace xml
    {
      namespace dom
      {
        // 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 tp, bool ap);

          // Content parsing.
          //
          bool
          more_content ()
          {
            return next_content_ != 0;
          }

          const xercesc::DOMElement&
          cur_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_content (bool text);

          // Attribute parsing.
          //
          bool
          more_attributes ()
          {
            return as_ > ai_;
          }

          const xercesc::DOMAttr&
          next_attribute ()
          {
            return *static_cast<const xercesc::DOMAttr*> (a_->item (ai_++));
          }

          void
          reset_attributes ()
          {
            ai_ = 0;
          }

          const xercesc::DOMElement&
          element () const
          {
            return element_;
          }

        private:
          parser (const parser&);

          parser&
          operator= (const parser&);

        private:
          const xercesc::DOMElement& element_;
          const xercesc::DOMNode* next_content_;

          const xercesc::DOMNamedNodeMap* a_;
          XMLSize_t ai_; // Index of the next DOMAttr.
          XMLSize_t as_; // Cached size of a_.
        };


        // Parsing flags.
        //
        const unsigned long dont_validate      = 0x00000400UL;
        const unsigned long no_muliple_imports = 0x00000800UL;

        template <typename C>
        XSD_DOM_AUTO_PTR<xercesc::DOMDocument>
        parse (xercesc::InputSource&,
               error_handler<C>&,
               const properties<C>&,
               unsigned long flags);

        template <typename C>
        XSD_DOM_AUTO_PTR<xercesc::DOMDocument>
        parse (xercesc::InputSource&,
               xercesc::DOMErrorHandler&,
               const properties<C>&,
               unsigned long flags);

        template <typename C>
        XSD_DOM_AUTO_PTR<xercesc::DOMDocument>
        parse (const std::basic_string<C>& uri,
               error_handler<C>&,
               const properties<C>&,
               unsigned long flags);

        template <typename C>
        XSD_DOM_AUTO_PTR<xercesc::DOMDocument>
        parse (const std::basic_string<C>& uri,
               xercesc::DOMErrorHandler&,
               const properties<C>&,
               unsigned long flags);
      }
    }
  }
}

#include <xsd/cxx/xml/dom/parsing-source.txx>

#endif // XSD_CXX_XML_DOM_PARSING_SOURCE_HXX