Revision 111, 1.8 kB
(checked in by mido, 17 years ago)
|
pridana knihovna XSD (a jeji chlebodarkyne XERCES), v ramci Win32 zprovoznen priklad tests/test_xsd_hello.cxx
|
Line | |
---|
1 | // file : xsd/cxx/tree/text.txx |
---|
2 | // author : Boris Kolpackov <boris@codesynthesis.com> |
---|
3 | // copyright : Copyright (c) 2005-2008 Code Synthesis Tools CC |
---|
4 | // license : GNU GPL v2 + exceptions; see accompanying LICENSE file |
---|
5 | |
---|
6 | #include <xercesc/dom/DOMText.hpp> |
---|
7 | |
---|
8 | #include <xsd/cxx/xml/string.hxx> |
---|
9 | |
---|
10 | #include <xsd/cxx/tree/exceptions.hxx> |
---|
11 | |
---|
12 | namespace xsd |
---|
13 | { |
---|
14 | namespace cxx |
---|
15 | { |
---|
16 | namespace tree |
---|
17 | { |
---|
18 | template <typename C> |
---|
19 | std::basic_string<C> |
---|
20 | text_content (const xercesc::DOMElement& e) |
---|
21 | { |
---|
22 | using xercesc::DOMNode; |
---|
23 | using xercesc::DOMText; |
---|
24 | |
---|
25 | DOMNode* n (e.getFirstChild ()); |
---|
26 | |
---|
27 | // Fast path. |
---|
28 | // |
---|
29 | if (n != 0 && |
---|
30 | n->getNodeType () == DOMNode::TEXT_NODE && |
---|
31 | n->getNextSibling () == 0) |
---|
32 | { |
---|
33 | DOMText* t (static_cast<DOMText*> (n)); |
---|
34 | |
---|
35 | // Berkeley DB XML DOM does not implement getLength(). |
---|
36 | // |
---|
37 | #ifndef DBXML_DOM |
---|
38 | return xml::transcode<C> (t->getData (), t->getLength ()); |
---|
39 | #else |
---|
40 | return xml::transcode<C> (t->getData ()); |
---|
41 | #endif |
---|
42 | } |
---|
43 | |
---|
44 | std::basic_string<C> r; |
---|
45 | |
---|
46 | for (; n != 0; n = n->getNextSibling ()) |
---|
47 | { |
---|
48 | switch (n->getNodeType ()) |
---|
49 | { |
---|
50 | case DOMNode::TEXT_NODE: |
---|
51 | case DOMNode::CDATA_SECTION_NODE: |
---|
52 | { |
---|
53 | DOMText* t (static_cast<DOMText*> (n)); |
---|
54 | |
---|
55 | // Berkeley DB XML DOM does not implement getLength(). |
---|
56 | // |
---|
57 | #ifndef DBXML_DOM |
---|
58 | r += xml::transcode<C> (t->getData (), t->getLength ()); |
---|
59 | #else |
---|
60 | r += xml::transcode<C> (t->getData ()); |
---|
61 | #endif |
---|
62 | break; |
---|
63 | } |
---|
64 | case DOMNode::ELEMENT_NODE: |
---|
65 | { |
---|
66 | throw expected_text_content<C> (); |
---|
67 | } |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | return r; |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | } |
---|