20 #ifndef DOMUTILS_H_WK0WAEA7
21 #define DOMUTILS_H_WK0WAEA7
27 #include "uscxml/config.h"
29 #include <xercesc/util/XMLString.hpp>
30 #include <xercesc/dom/DOM.hpp>
46 #define HAS_ATTR(elem, attr) (elem)->hasAttribute(X(attr))
47 #define HAS_ATTR_CAST(elem, attr) HAS_ATTR(static_cast<const DOMElement*>(elem), attr)
48 #define ATTR(elem, attr) std::string(X((elem)->getAttribute(X(attr))))
49 #define ATTR_CAST(elem, attr) ATTR(static_cast<const DOMElement*>(elem), attr)
50 #define TAGNAME(elem) std::string(X((elem)->getTagName()))
51 #define TAGNAME_CAST(elem) TAGNAME(static_cast<const DOMElement*>(elem))
52 #define LOCALNAME(elem) std::string(X((elem)->getLocalName()))
53 #define LOCALNAME_CAST(elem) LOCALNAME(static_cast<const DOMElement*>(elem))
62 static const XERCESC_NS::DOMNode* getNearestAncestor(
const XERCESC_NS::DOMNode* node,
const std::string tagName);
63 static bool isDescendant(
const XERCESC_NS::DOMNode* s1,
const XERCESC_NS::DOMNode* s2);
66 static bool hasIntersection(
const std::list<XERCESC_NS::DOMElement*>& l1,
67 const std::list<XERCESC_NS::DOMElement*>& l2);
68 static bool isMember(
const XERCESC_NS::DOMElement* node,
const std::list<XERCESC_NS::DOMElement*>& list);
69 static bool isMember(
const XERCESC_NS::DOMNode* node,
const std::list<XERCESC_NS::DOMNode*>& list);
70 static bool isMember(
const XERCESC_NS::DOMNode* node,
const XERCESC_NS::DOMNodeList* list);
72 static std::string xPathForNode(
const XERCESC_NS::DOMNode* node,
73 const std::string& ns =
"");
74 static std::string idForNode(
const XERCESC_NS::DOMNode* node);
76 static std::list<XERCESC_NS::DOMNode*> getElementsByType(
const XERCESC_NS::DOMNode* root,
77 XERCESC_NS::DOMNode::NodeType type);
79 static std::list<XERCESC_NS::DOMElement*> inPostFixOrder(
const std::set<std::string>& elements,
80 const XERCESC_NS::DOMElement* root,
81 const bool includeEmbeddedDoc =
false);
83 static std::list<XERCESC_NS::DOMElement*> inDocumentOrder(
const std::set<std::string>& elements,
84 const XERCESC_NS::DOMElement* root,
85 const bool includeEmbeddedDoc =
false);
87 static std::list<XERCESC_NS::DOMElement*> filterChildElements(
const std::string& tagName,
88 const XERCESC_NS::DOMElement* node,
89 bool recurse =
false);
91 static std::list<XERCESC_NS::DOMElement*> filterChildElements(
const std::string& tagName,
92 const std::list<XERCESC_NS::DOMElement*>& nodeSet,
93 bool recurse =
false);
95 static std::list<XERCESC_NS::DOMNode*> filterChildType(
const XERCESC_NS::DOMNode::NodeType type,
96 const XERCESC_NS::DOMNode* node,
97 bool recurse =
false);
99 static std::list<XERCESC_NS::DOMNode*> filterChildType(
const XERCESC_NS::DOMNode::NodeType type,
100 const std::list<XERCESC_NS::DOMNode*>& nodeSet,
101 bool recurse =
false);
104 static void inPostFixOrder(
const std::set<std::string>& elements,
105 const XERCESC_NS::DOMElement* root,
106 const bool includeEmbeddedDoc,
107 std::list<XERCESC_NS::DOMElement*>& nodes);
109 static void inDocumentOrder(
const std::set<std::string>& elements,
110 const XERCESC_NS::DOMElement* root,
111 const bool includeEmbeddedDoc,
112 std::list<XERCESC_NS::DOMElement*>& nodes);
118 #define XML_PREFIX(element) X(element->getPrefix() ? X(element->getPrefix()).str() + ":" : "")
124 _localForm = other._localForm;
125 _otherForm = XERCESC_NS::XMLString::replicate(other._otherForm);
126 _deallocOther =
true;
128 void operator=(
X const &other) {
129 _localForm = other._localForm;
130 _otherForm = XERCESC_NS::XMLString::replicate(other._otherForm);
131 _deallocOther =
true;
134 X(
const XMLCh*
const toTranscode) {
135 if (toTranscode != NULL) {
137 char* tmp = XERCESC_NS::XMLString::transcode(toTranscode);
138 _localForm = std::string(tmp);
139 XERCESC_NS::XMLString::release(&tmp);
142 _deallocOther =
false;
145 X(
const std::string& fromTranscode) {
147 _localForm = fromTranscode;
148 _otherForm = XERCESC_NS::XMLString::transcode(fromTranscode.c_str());
149 _deallocOther =
true;
152 X(
const char*
const fromTranscode) {
154 _localForm = fromTranscode;
155 _otherForm = XERCESC_NS::XMLString::transcode(fromTranscode);
156 _deallocOther =
true;
159 X(
char* fromTranscode) {
161 _localForm = fromTranscode;
162 _otherForm = XERCESC_NS::XMLString::transcode(fromTranscode);
163 _deallocOther =
true;
168 _deallocOther =
false;
173 XERCESC_NS::XMLString::release(&_otherForm);
176 const std::string& str()
const {
180 operator const XMLCh* () {
181 assert(_otherForm != NULL);
186 return _localForm.size() > 0;
189 operator std::string () {
194 friend USCXML_API std::ostream& operator<< (std::ostream& os,
const X& data);
198 std::string _localForm;
202 USCXML_API std::ostream& operator<< (std::ostream& os,
const X& xmlString);
203 USCXML_API std::ostream& operator<< (std::ostream& os,
const XERCESC_NS::DOMNode& node);
Definition: InterpreterIssue.cpp:33