20 #ifndef DOMUTILS_H_WK0WAEA7
21 #define DOMUTILS_H_WK0WAEA7
28 #include <xercesc/util/XMLString.hpp>
29 #include <xercesc/dom/DOM.hpp>
31 #define HAS_ATTR(elem, attr) (elem)->hasAttribute(attr)
32 #define HAS_ATTR_CAST(elem, attr) HAS_ATTR(static_cast<const DOMElement*>(elem), attr)
33 #define ATTR(elem, attr) std::string(X((elem)->getAttribute(attr)))
34 #define ATTR_CAST(elem, attr) ATTR(static_cast<const DOMElement*>(elem), attr)
35 #define TAGNAME(elem) std::string(X((elem)->getTagName()))
36 #define TAGNAME_CAST(elem) TAGNAME(static_cast<const DOMElement*>(elem))
37 #define LOCALNAME(elem) std::string(X((elem)->getLocalName()))
38 #define LOCALNAME_CAST(elem) LOCALNAME(static_cast<const DOMElement*>(elem))
45 static const XERCESC_NS::DOMElement* getNearestAncestor(
const XERCESC_NS::DOMNode* node,
const std::string tagName);
46 static bool isDescendant(
const XERCESC_NS::DOMNode* s1,
const XERCESC_NS::DOMNode* s2);
48 static bool hasIntersection(
const std::list<XERCESC_NS::DOMElement*>& l1,
49 const std::list<XERCESC_NS::DOMElement*>& l2);
50 static bool isMember(
const XERCESC_NS::DOMElement* node,
const std::list<XERCESC_NS::DOMElement*>& list);
51 static bool isMember(
const XERCESC_NS::DOMNode* node,
const std::list<XERCESC_NS::DOMNode*>& list);
52 static bool isMember(
const XERCESC_NS::DOMNode* node,
const XERCESC_NS::DOMNodeList* list);
54 static std::string xPathForNode(
const XERCESC_NS::DOMNode* node,
const std::string& ns =
"");
55 static std::string idForNode(
const XERCESC_NS::DOMNode* node);
57 static std::list<XERCESC_NS::DOMElement*> inPostFixOrder(
const std::set<std::string>& elements,
58 const XERCESC_NS::DOMElement* root,
59 const bool includeEmbeddedDoc =
false) {
60 return filterElementGeneric(elements, root, POSTFIX, includeEmbeddedDoc,
true);
63 static std::list<XERCESC_NS::DOMElement*> inDocumentOrder(
const std::set<std::string>& elements,
64 const XERCESC_NS::DOMElement* root,
65 const bool includeEmbeddedDoc =
false) {
66 return filterElementGeneric(elements, root, DOCUMENT, includeEmbeddedDoc,
true);
69 static std::list<XERCESC_NS::DOMElement*> filterChildElements(
const std::string& tagName,
70 const XERCESC_NS::DOMElement* node,
71 bool recurse =
false) {
72 return filterElementGeneric({ tagName }, node, (recurse ? DOCUMENT : NO_RECURSE),
true,
false);
75 static std::list<XERCESC_NS::DOMElement*> filterChildElements(
const std::string& tagName,
76 const std::list<XERCESC_NS::DOMElement*>& nodeSet,
77 bool recurse =
false);
79 static std::list<XERCESC_NS::DOMNode*> filterChildType(
const XERCESC_NS::DOMNode::NodeType type,
80 const XERCESC_NS::DOMNode* node,
81 bool recurse =
false) {
82 return filterTypeGeneric({ type }, node, (recurse ? DOCUMENT : NO_RECURSE),
true,
false);
86 static std::list<XERCESC_NS::DOMNode*> filterChildType(
const XERCESC_NS::DOMNode::NodeType type,
87 const std::list<XERCESC_NS::DOMNode*>& nodeSet,
88 bool recurse =
false);
96 static void filterElementGeneric(
const std::set<std::string>& elements,
97 std::list<XERCESC_NS::DOMElement*>& result,
98 const XERCESC_NS::DOMElement* root,
100 const bool includeEmbeddedDoc,
101 const bool includeRoot);
103 static std::list<XERCESC_NS::DOMElement*> filterElementGeneric(
const std::set<std::string>& elements,
104 const XERCESC_NS::DOMElement* root,
106 const bool includeEmbeddedDoc,
107 const bool includeRoot);
109 static void filterTypeGeneric(
const std::set<XERCESC_NS::DOMNode::NodeType>& types,
110 std::list<XERCESC_NS::DOMNode*>& result,
111 const XERCESC_NS::DOMNode* root,
113 const bool includeEmbeddedDoc,
114 const bool includeRoot);
116 static std::list<XERCESC_NS::DOMNode*> filterTypeGeneric(
const std::set<XERCESC_NS::DOMNode::NodeType>& types,
117 const XERCESC_NS::DOMNode* root,
119 const bool includeEmbeddedDoc,
120 const bool includeRoot);
125 #define XML_PREFIX(element) X(element->getPrefix() ? X(element->getPrefix()).str() + ":" : "")
138 _localForm = other._localForm;
139 _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm);
140 _deallocOther =
true;
143 X(
const XMLCh*
const toTranscode) {
145 if (toTranscode != NULL) {
147 char* tmp = XERCESC_NS::XMLString::transcode(toTranscode);
148 _localForm = std::string(tmp);
149 XERCESC_NS::XMLString::release(&tmp);
152 _deallocOther =
false;
155 X(
const std::string& fromTranscode) {
158 _localForm = fromTranscode;
159 _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode.c_str());
160 _deallocOther =
true;
163 X(
const char*
const fromTranscode) {
165 if (!_xercesIsInit) {
167 ::xercesc_3_1::XMLPlatformUtils::Initialize();
168 _xercesIsInit =
true;
169 }
catch (
const XERCESC_NS::XMLException& toCatch) {
170 throw (
"Cannot initialize XercesC: " +
X(toCatch.getMessage()).str());
175 _localForm = fromTranscode;
176 _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode);
177 _deallocOther =
true;
180 X(
char* fromTranscode) {
183 _localForm = fromTranscode;
184 _unicodeForm = XERCESC_NS::XMLString::transcode(fromTranscode);
185 _deallocOther =
true;
191 _deallocOther =
false;
197 XERCESC_NS::XMLString::release(&_unicodeForm);
200 const std::string& str()
const {
204 operator XMLCh* ()
const {
205 assert(_unicodeForm != NULL);
209 void operator=(
X const &other) {
210 _localForm = other._localForm;
211 _unicodeForm = XERCESC_NS::XMLString::replicate(other._unicodeForm);
212 _deallocOther =
true;
215 bool operator==(
const X& other)
const {
216 return (_unicodeForm == other._unicodeForm) != 0;
219 bool operator!=(
const X& other)
const {
220 return !(_unicodeForm == other._unicodeForm);
223 bool operator<(
const X& other)
const {
224 return XERCESC_NS::XMLString::compareString(_unicodeForm, other._unicodeForm) < 0;
228 return _localForm.size() > 0;
231 operator std::string () {
236 friend USCXML_API std::ostream& operator<< (std::ostream& os,
const X& data);
240 std::string _localForm;
242 bool _xercesIsInit =
false;
252 void operator=(X
const &other) {
253 localForm = other.localForm;
254 if (unicodeForm != NULL) {
255 XERCESC_NS::XMLString::release(&unicodeForm);
257 unicodeForm = XERCESC_NS::XMLString::replicate(other.unicodeForm);
261 localForm = other.localForm;
262 unicodeForm = XERCESC_NS::XMLString::replicate(other.unicodeForm);
265 X(
const char*
const toTranscode) {
266 if (toTranscode != NULL) {
267 localForm = toTranscode;
268 unicodeForm = XERCESC_NS::XMLString::transcode(toTranscode);
272 X(
const XMLCh* toTranscode) {
273 if (toTranscode != NULL) {
274 unicodeForm = XERCESC_NS::XMLString::replicate(toTranscode);
275 localForm = XERCESC_NS::XMLString::transcode(toTranscode);
279 X(
const std::string& toTranscode) {
280 localForm = toTranscode;
281 unicodeForm = XERCESC_NS::XMLString::transcode(toTranscode.c_str());
285 if (unicodeForm != NULL) {
286 XERCESC_NS::XMLString::release(&unicodeForm);
290 operator XMLCh* ()
const {
294 operator const std::string& () {
298 const std::string& str()
const {
302 const XMLCh* unicode()
const {
308 friend USCXML_API std::ostream& operator<< (std::ostream& os,
const X& data);
311 XMLCh* unicodeForm = NULL;
312 std::string localForm;
318 static const X kXMLCharScxml = X(
"scxml");
319 static const X kXMLCharState = X(
"state");
320 static const X kXMLCharParallel = X(
"parallel");
321 static const X kXMLCharTransition = X(
"transition");
322 static const X kXMLCharInitial = X(
"initial");
323 static const X kXMLCharFinal = X(
"final");
324 static const X kXMLCharOnEntry = X(
"onentry");
325 static const X kXMLCharOnExit = X(
"onexit");
326 static const X kXMLCharHistory = X(
"history");
328 static const X kXMLCharRaise = X(
"raise");
329 static const X kXMLCharIf = X(
"if");
330 static const X kXMLCharElseIf = X(
"elseif");
331 static const X kXMLCharElse = X(
"else");
332 static const X kXMLCharForEach = X(
"foreach");
333 static const X kXMLCharLog = X(
"log");
335 static const X kXMLCharDataModel = X(
"datamodel");
336 static const X kXMLCharData = X(
"data");
337 static const X kXMLCharAssign = X(
"assign");
338 static const X kXMLCharContent = X(
"content");
339 static const X kXMLCharParam = X(
"param");
340 static const X kXMLCharScript = X(
"script");
342 static const X kXMLCharInvokeId = X(
"invokeid");
343 static const X kXMLCharId = X(
"id");
344 static const X kXMLCharIdLocation = X(
"idlocation");
345 static const X kXMLCharEvent = X(
"event");
346 static const X kXMLCharEventExpr = X(
"eventexpr");
347 static const X kXMLCharTarget = X(
"target");
348 static const X kXMLCharTargetExpr = X(
"targetexpr");
349 static const X kXMLCharSource = X(
"src");
350 static const X kXMLCharSourceExpr = X(
"srcexpr");
351 static const X kXMLCharType = X(
"type");
352 static const X kXMLCharTypeExpr = X(
"typeexpr");
353 static const X kXMLCharDelay = X(
"delay");
354 static const X kXMLCharDelayExpr = X(
"delayexpr");
355 static const X kXMLCharSendId = X(
"sendid");
356 static const X kXMLCharSendIdExpr = X(
"sendidexpr");
357 static const X kXMLCharCond = X(
"cond");
358 static const X kXMLCharLocation = X(
"location");
359 static const X kXMLCharArray = X(
"array");
360 static const X kXMLCharItem = X(
"item");
361 static const X kXMLCharIndex = X(
"index");
362 static const X kXMLCharLabel = X(
"label");
363 static const X kXMLCharExpr = X(
"expr");
364 static const X kXMLCharNameList = X(
"namelist");
365 static const X kXMLCharAutoForward = X(
"autoforward");
366 static const X kXMLCharName = X(
"name");
367 static const X kXMLCharBinding = X(
"binding");
369 USCXML_API std::ostream& operator<< (std::ostream& os,
const X& xmlString);
370 USCXML_API std::ostream& operator<< (std::ostream& os,
const XERCESC_NS::DOMNode& node);
Definition: Breakpoint.cpp:26