Branch data Line data Source code
1 : : // file : xsd/cxx/tree/text.txx
2 : : // copyright : Copyright (c) 2005-2014 Code Synthesis Tools CC
3 : : // license : GNU GPL v2 + exceptions; see accompanying LICENSE file
4 : :
5 : : #include <xercesc/dom/DOMText.hpp>
6 : :
7 : : #include <xsd/cxx/xml/string.hxx>
8 : :
9 : : #include <xsd/cxx/tree/exceptions.hxx>
10 : :
11 : : namespace xsd
12 : : {
13 : : namespace cxx
14 : : {
15 : : namespace tree
16 : : {
17 : : template <typename C>
18 : : std::basic_string<C>
19 : 0 : text_content (const xercesc::DOMElement& e)
20 : : {
21 : : using xercesc::DOMNode;
22 : : using xercesc::DOMText;
23 : :
24 : 0 : DOMNode* n (e.getFirstChild ());
25 : :
26 : : // Fast path.
27 : : //
28 [ # # # # : 0 : if (n != 0 &&
# # ][ # # ]
29 : 0 : n->getNodeType () == DOMNode::TEXT_NODE &&
30 : 0 : n->getNextSibling () == 0)
31 : : {
32 : : DOMText* t (static_cast<DOMText*> (n));
33 : 0 : return xml::transcode<C> (t->getData (), t->getLength ());
34 : : }
35 : :
36 : : std::basic_string<C> r;
37 : :
38 [ # # ][ # # ]: 0 : for (; n != 0; n = n->getNextSibling ())
39 : : {
40 [ # # ]: 0 : switch (n->getNodeType ())
[ # # # ]
41 : : {
42 : : case DOMNode::TEXT_NODE:
43 : : case DOMNode::CDATA_SECTION_NODE:
44 : : {
45 : : DOMText* t (static_cast<DOMText*> (n));
46 [ # # ][ # # ]: 0 : r += xml::transcode<C> (t->getData (), t->getLength ());
47 : 0 : break;
48 : : }
49 : : case DOMNode::ELEMENT_NODE:
50 : : {
51 : 0 : throw expected_text_content<C> ();
52 : : }
53 : : default:
54 : : break; // ignore
55 : : }
56 : : }
57 : :
58 : : return r;
59 : : }
60 : : }
61 : : }
62 : : }
|