mbxmlutils 1.3.0 Multi-Body XML Utils

dom.h
1 #ifndef _MBXMLUTILSHELPER_DOM_H_
2 #define _MBXMLUTILSHELPER_DOM_H_
3
4 #include <fmatvec/atom.h>
5 #include <string>
6 #include <utility>
7 #include <vector>
8 #include <map>
9 #include <set>
10 #include <variant>
11 #include <boost/filesystem.hpp>
12 #include <xercesc/dom/DOMErrorHandler.hpp>
13 #include <xercesc/dom/DOMElement.hpp>
14 #include <xercesc/dom/DOMText.hpp>
15 #include <xercesc/dom/DOMLSParser.hpp>
16 #include <xercesc/dom/DOMLocator.hpp>
17 #include <xercesc/dom/DOMUserDataHandler.hpp>
18 #include <xercesc/dom/DOMDocument.hpp>
19 #include <xercesc/util/TransService.hpp>
20 #include <xercesc/util/XMLEntityResolver.hpp>
21 #include <xercesc/framework/psvi/PSVIHandler.hpp>
22 #include <boost/lexical_cast.hpp>
23 #include <boost/container/small_vector.hpp>
24 #include <fmatvec/toString.h>
25
26 namespace XERCES_CPP_NAMESPACE {
27 class DOMProcessingInstruction;
28 class DOMImplementation;
29 class AbstractDOMParser;
30 }
31
32 namespace boost {
33 template<> std::vector<double> lexical_cast(const std::string& str);
34 template<> std::vector<std::vector<double>> lexical_cast(const std::string& str);
35 template<> std::vector<int> lexical_cast(const std::string& str);
36 template<> std::vector<std::vector<int>> lexical_cast(const std::string& str);
37 template<> bool lexical_cast<bool>(const std::string& arg);
38 }
39
40 namespace {
41
42 template<class T>
43 struct CheckSize {
44 static void check(const xercesc::DOMElement *me, const T &value, int r, int c);
45 };
46 template<class T>
47 struct CheckSize<std::vector<T>> {
48 static void check(const xercesc::DOMElement *me, const std::vector<T> &value, int r, int c);
49 };
50 template<class T>
51 struct CheckSize<std::vector<std::vector<T>>> {
52 static void check(const xercesc::DOMElement *me, const std::vector<std::vector<T>> &value, int r, int c);
53 };
54
55 }
56
57 namespace MBXMLUtils {
58
59 template<class T> struct XercesUniquePtrDeleter { void operator()(T *n) { if(n) n->release(); } };
61 template<class T> using XercesUniquePtr = std::unique_ptr<T, XercesUniquePtrDeleter<T>>;
62
63 // forward declaration
64 template<typename DOMDocumentType>
65 class DOMDocumentWrapper;
66 template<typename DOMDocumentType>
67 DOMDocumentWrapper<DOMDocumentType> D(DOMDocumentType *me);
68 template<typename DOMElementType>
69 class DOMElementWrapper;
70 template<typename DOMElementType>
71 DOMElementWrapper<DOMElementType> E(DOMElementType *me);
72
74 class InitXerces {
75 public:
76 InitXerces() {
77 xercesc::XMLPlatformUtils::Initialize();
78 }
79 ~InitXerces() {
80 xercesc::XMLPlatformUtils::Terminate();
81 }
82 };
83
86 class X {
87 public:
88 const XMLCh *operator%(const std::string &str) {
89 if(str.empty())
90 return &xercesc::chNull;
91 const XMLCh *unicode=xercesc::TranscodeFromStr(reinterpret_cast<const XMLByte*>(str.c_str()), str.length(), "UTF8").adopt();
92 store.emplace_back(unicode, &releaseXMLCh);
93 return unicode;
94 }
95 const XMLCh *operator()(const std::string &str) { return operator%(str); }
96 std::string operator%(const XMLCh *unicode) {
97 if(!unicode || unicode[0]==0)
98 return {};
99 return reinterpret_cast<const char*>(xercesc::TranscodeToStr(unicode, "UTF8").str());
100 }
101 std::string operator()(const XMLCh *unicode) { return operator%(unicode); }
102 static void releaseXMLCh(const XMLCh *s) { xercesc::XMLPlatformUtils::fgMemoryManager->deallocate(const_cast<XMLCh*>(s)); }
103 private:
104 boost::container::small_vector<std::unique_ptr<const XMLCh, decltype(&releaseXMLCh)>, 1> store;
105 };
106
109 class FQN : public std::pair<std::string, std::string> {
110 public:
112 FQN() = default;
114 FQN(const std::string &name) : std::pair<std::string, std::string>("", name) {}
116 FQN(const char *name) : std::pair<std::string, std::string>("", name) {}
118 FQN(const std::string &ns, const std::string &name) : std::pair<std::string, std::string>(ns, name) {}
119 };
120
122 class NamespaceURI {
123 public:
124 NamespaceURI(std::string nsuri_) : nsuri(std::move(nsuri_)) {}
125 FQN operator%(const std::string &localName) const { return {nsuri, localName}; }
126 const std::string& getNamespaceURI() const { return nsuri; }
127 private:
128 std::string nsuri;
129 };
130
132 const NamespaceURI XINCLUDE("http://www.w3.org/2001/XInclude");
134 const NamespaceURI XMLNS("http://www.w3.org/2000/xmlns/");
136 const NamespaceURI PV("http://www.mbsim-env.de/MBXMLUtils");
138 const NamespaceURI XMLCATALOG("urn:oasis:names:tc:entity:xmlns:xml:catalog");
139
142 class EmbedDOMLocator : public xercesc::DOMLocator {
143 public:
144 EmbedDOMLocator(const boost::filesystem::path &file_, int row_, int embedCount_, std::string xpath_) : DOMLocator(),
145 file(x%file_.string()), row(row_), embedCount(embedCount_), xpath(std::move(xpath_)) {}
146 EmbedDOMLocator(const EmbedDOMLocator &src) : DOMLocator(),
147 file(x%(X()%src.file)), row(src.row), embedCount(src.embedCount), xpath(src.xpath) {}
148 EmbedDOMLocator& operator=(const EmbedDOMLocator &src) {
149 file=x%(X()%src.file);
150 row=src.row;
151 embedCount=src.embedCount;
152 xpath=src.xpath;
153 return *this;
154 }
155 ~EmbedDOMLocator() override = default;
156 EmbedDOMLocator(const EmbedDOMLocator &&src) = delete;
157 EmbedDOMLocator& operator=(const EmbedDOMLocator &&src) = delete;
158 XMLFileLoc getLineNumber() const override { return row; }
159 XMLFileLoc getColumnNumber() const override { return 0; }
160 XMLFilePos getByteOffset() const override { return ~(XMLFilePos(0)); }
161 XMLFilePos getUtf16Offset() const override { return ~(XMLFilePos(0)); }
162 xercesc::DOMNode *getRelatedNode() const override { return nullptr; }
163 const XMLCh *getURI() const override { return file; }
164 int getEmbedCount() const { return embedCount; }
165 const std::string& getRootXPathExpression() const { return xpath; }
166 private:
167 X x;
168 const XMLCh *file;
169 int row;
170 int embedCount;
171 std::string xpath;
172 };
173
174 // Exception wrapping for DOMEvalException.
175 // Rethrow a exception as DOMEvalException with context e, a DOMEvalException is just rethrown unchanged.
176 #define RETHROW_AS_DOMEVALEXCEPTION(e) \
177 catch(MBXMLUtils::DOMEvalException &ex) { \
178 throw ex; \
179 } \
180 catch(const std::exception &ex) { \
181 throw DOMEvalException(ex.what(), e); \
182 }
183
186 class DOMEvalException : public std::exception {
187 friend class DOMParser;
188 friend class DOMErrorPrinter;
189 public:
190 DOMEvalException() = default;
191 DOMEvalException(const std::string &errorMsg_, const xercesc::DOMNode *n);
192 void appendContext(const xercesc::DOMNode *n, int lineNr=0);
193 const std::string& getMessage() const { return errorMsg; }
194 void setMessage(const std::string& errorMsg_) { errorMsg=errorMsg_; }
195 void setSubsequentError(bool sse) { subsequentError=sse; }
196 const char* what() const noexcept override;
197 xercesc::DOMNode::NodeType getNodeType() const { return nodeType; }
198 protected:
199 DOMEvalException(const std::string &errorMsg_, const xercesc::DOMLocator &loc);
200 private:
227 static std::string convertToString(const EmbedDOMLocator &loc, const std::string &message, bool subsequentError=false);
228
229 bool subsequentError{false};
230 std::string errorMsg;
231 std::vector<EmbedDOMLocator> locationStack;
232 mutable std::string whatStr;
233 xercesc::DOMNode::NodeType nodeType { static_cast<xercesc::DOMNode::NodeType>(-1) };
234 };
235
237 class DOMErrorPrinter: public xercesc::DOMErrorHandler, virtual public fmatvec::Atom
238 {
239 public:
240 DOMErrorPrinter() = default;
241 bool handleError(const xercesc::DOMError&) override;
242 bool hasError() { return errorSet; }
243 const DOMEvalException& getError() { return error; }
244 void resetError() { errorSet=false; }
245 private:
246 bool errorSet{false};
247 DOMEvalException error;
248 };
249
251 template<typename DOMElementType>
252 class DOMElementWrapper {
253 public:
255 DOMElementWrapper(DOMElementType *me_) : me(me_) {}
257 FQN getTagName() const { return FQN(X()%me->getNamespaceURI(), X()%me->getLocalName()); }
259 const xercesc::DOMElement *getFirstElementChildNamed(const FQN &name) const;
261 xercesc::DOMElement *getFirstElementChildNamed(const FQN &name);
263 const xercesc::DOMElement *getNextElementSiblingNamed(const FQN &name) const;
265 xercesc::DOMElement *getNextElementSiblingNamed(const FQN &name);
267 const xercesc::DOMProcessingInstruction *getFirstProcessingInstructionChildNamed(const std::string &target) const;
269 xercesc::DOMProcessingInstruction *getFirstProcessingInstructionChildNamed(const std::string &target);
271 void addProcessingInstructionChildNamed(const std::string &target, const std::string &data);
273 std::string getEmbedData(const std::string &name) const;
276 void addEmbedData(const std::string &name, const std::string &data);
278 const xercesc::DOMComment *getFirstCommentChild() const;
280 xercesc::DOMComment *getFirstCommentChild();
285 const xercesc::DOMText *getFirstTextChild() const;
290 xercesc::DOMText *getFirstTextChild();
292 template<class T> T getText(int r=0, int c=0) const {
293 try {
294 auto textEle=E(me)->getFirstTextChild();
295 auto text=textEle ? X()%textEle->getData() : "";
296 auto ret=boost::lexical_cast<T>(text);
297 CheckSize<T>::check(me, ret, r, c);
298 return ret;
299 }
300 catch(const boost::bad_lexical_cast &ex) {
301 throw DOMEvalException(ex.what(), me);
302 }
303 catch(const std::exception &ex) {
304 throw DOMEvalException(ex.what(), me);
305 }
306 }
307
308 template<class T> void addElementText(const FQN &name, const T &value) {
309 xercesc::DOMElement *ele=D(me->getOwnerDocument())->createElement(name);
310 ele->insertBefore(me->getOwnerDocument()->createTextNode(MBXMLUtils::X()%fmatvec::toString(value)), nullptr);
311 me->insertBefore(ele, nullptr);
312 }
315 bool isDerivedFrom(const FQN &baseTypeName) const;
321 boost::filesystem::path getOriginalFilename(bool skipThis=false,
322 const xercesc::DOMElement *&found=DOMElementWrapper<DOMElementType>::dummyArg) const;
327 void setOriginalFilename(boost::filesystem::path orgFileName=boost::filesystem::path());
330 boost::filesystem::path convertPath(const boost::filesystem::path &relPath) const;
333 int getLineNumber() const;
336 int getEmbedCountNumber() const;
339 void setEmbedCountNumber(int embedCount);
342 int getEmbedXPathCount() const;
345 void setEmbedXPathCount(int xPathCount);
350 std::string getRootXPathExpression() const;
353 std::vector<int> getElementLocation() const;
355 int getOriginalElementLineNumber() const;
357 void setOriginalElementLineNumber(int lineNr);
359 std::string getAttribute(const FQN &name) const;
361 FQN getAttributeQName(const FQN &name) const;
363 const xercesc::DOMAttr* getAttributeNode(const FQN &name) const;
365 xercesc::DOMAttr* getAttributeNode(const FQN &name);
367 template<class T>
368 void setAttribute(const FQN &name, const T &value) {
369 me->setAttributeNS(X()%name.first, X()%name.second, X()%fmatvec::toString(value));
370 }
372 void setAttribute(const FQN &name, const FQN &value);
374 bool hasAttribute(const FQN &name) const;
376 void removeAttribute(const FQN &name);
378 typename std::conditional<std::is_same<DOMElementType, const xercesc::DOMElement>::value,
379 const DOMElementWrapper*, DOMElementWrapper*>::type operator->() {
380 return this;
381 }
382 static const xercesc::DOMElement *dummyArg;
383 private:
384 DOMElementType *me;
385 };
387 template<typename DOMElementType>
388 DOMElementWrapper<DOMElementType> E(DOMElementType *me) { return DOMElementWrapper<DOMElementType>(me); }
390 template<typename DOMElementType>
391 DOMElementWrapper<DOMElementType> E(const std::shared_ptr<DOMElementType> &me) { return DOMElementWrapper<DOMElementType>(me.get()); }
393 template<typename DOMElementType>
394 DOMElementWrapper<DOMElementType> E(const XercesUniquePtr<DOMElementType> &me) { return DOMElementWrapper<DOMElementType>(me.get()); }
395
396 template<> const xercesc::DOMElement *DOMElementWrapper< xercesc::DOMElement>::dummyArg;
397 template<> const xercesc::DOMElement *DOMElementWrapper<const xercesc::DOMElement>::dummyArg;
398
400 template<typename DOMAttrType>
401 class DOMAttrWrapper {
402 public:
404 DOMAttrWrapper(DOMAttrType *me_) : me(me_) {}
407 bool isDerivedFrom(const FQN &baseTypeName) const;
410 std::string getRootXPathExpression() const;
412 typename std::conditional<std::is_same<DOMAttrType, const xercesc::DOMAttr>::value,
413 const DOMAttrWrapper*, DOMAttrWrapper*>::type operator->() {
414 return this;
415 }
416 private:
417 DOMAttrType *me;
418 };
420 template<typename DOMAttrType>
421 DOMAttrWrapper<DOMAttrType> A(DOMAttrType *me) { return DOMAttrWrapper<DOMAttrType>(me); }
423 template<typename DOMAttrType>
424 DOMAttrWrapper<DOMAttrType> A(const std::shared_ptr<DOMAttrType> &me) { return DOMAttrWrapper<DOMAttrType>(me.get()); }
426 template<typename DOMAttrType>
427 DOMAttrWrapper<DOMAttrType> A(const XercesUniquePtr<DOMAttrType> &me) { return DOMAttrWrapper<DOMAttrType>(me.get()); }
428
429 class DOMParser;
430
432 template<typename DOMDocumentType>
433 class DOMDocumentWrapper {
434 public:
436 DOMDocumentWrapper(DOMDocumentType *me_) : me(me_) {}
441 XercesUniquePtr<xercesc::DOMElement> validate();
444 xercesc::DOMElement* createElement(const FQN &name);
446 std::shared_ptr<DOMParser> getParser() const;
449 boost::filesystem::path getDocumentFilename() const;
454 xercesc::DOMNode* evalRootXPathExpression(std::string xpathExpression, xercesc::DOMElement* context=nullptr);
457 xercesc::DOMElement* locateElement(const std::vector<int> &idx) const;
459 typename std::conditional<std::is_same<DOMDocumentType, const xercesc::DOMDocument>::value,
460 const DOMDocumentWrapper*, DOMDocumentWrapper*>::type operator->() {
461 return this;
462 }
463 private:
464 DOMDocumentType *me;
465 };
467 template<typename DOMDocumentType>
468 DOMDocumentWrapper<DOMDocumentType> D(DOMDocumentType *me) { return DOMDocumentWrapper<DOMDocumentType>(me); }
470 template<typename DOMDocumentType>
471 DOMDocumentWrapper<DOMDocumentType> D(const std::shared_ptr<DOMDocumentType> &me) { return DOMDocumentWrapper<DOMDocumentType>(me.get()); }
473 template<typename DOMDocumentType>
474 DOMDocumentWrapper<DOMDocumentType> D(const XercesUniquePtr<DOMDocumentType> &me) { return DOMDocumentWrapper<DOMDocumentType>(me.get()); }
475
476 class LocationInfoFilter : public xercesc::DOMLSParserFilter {
477 public:
478 void setParser(DOMParser *parser_) { parser=parser_; }
479 xercesc::DOMLSParserFilter::FilterAction acceptNode(xercesc::DOMNode *n) override;
480 xercesc::DOMLSParserFilter::FilterAction startElement(xercesc::DOMElement *e) override;
481 xercesc::DOMNodeFilter::ShowType getWhatToShow() const override;
482 private:
483 DOMParser *parser;
484 };
485
486 class TypeDerivativeHandler : public xercesc::PSVIHandler, virtual public fmatvec::Atom {
487 public:
488 void setParser(DOMParser *parser_) { parser=parser_; }
489 void handleElementPSVI(const XMLCh *localName, const XMLCh *uri, xercesc::PSVIElement *info) override;
490 void handleAttributesPSVI(const XMLCh *localName, const XMLCh *uri, xercesc::PSVIAttributeList *psviAttributes) override;
491 private:
492 DOMParser *parser;
493 };
494
495 class UserDataHandler : public xercesc::DOMUserDataHandler {
496 public:
497 void handle(DOMOperationType operation, const XMLCh* key, void *data, const xercesc::DOMNode *src, xercesc::DOMNode *dst) override;
498 };
499
500 extern UserDataHandler userDataHandler;
501
502 class EntityResolver : public xercesc::XMLEntityResolver {
503 public:
504 void setParser(DOMParser *parser_) { parser=parser_; }
505 xercesc::InputSource* resolveEntity(xercesc::XMLResourceIdentifier *resourceIdentifier) override;
506 private:
507 DOMParser *parser;
508 };
509
511 class DOMParser : public std::enable_shared_from_this<DOMParser> {
512 friend class TypeDerivativeHandler;
513 friend class LocationInfoFilter;
514 friend class UserDataHandler;
515 friend class EntityResolver;
516 friend class DOMElementWrapper<xercesc::DOMElement>;
517 friend class DOMElementWrapper<const xercesc::DOMElement>;
518 template<typename> friend class DOMDocumentWrapper;
519 public:
523 static std::shared_ptr<DOMParser> create(const std::variant<boost::filesystem::path, xercesc::DOMElement*> &xmlCatalog=static_cast<xercesc::DOMElement*>(nullptr));
527 std::shared_ptr<xercesc::DOMDocument> parse(const boost::filesystem::path &inputSource,
528 std::vector<boost::filesystem::path> *dependencies=nullptr,
529 bool doXInclude=true);
532 static void serialize(xercesc::DOMNode *n, const boost::filesystem::path &outputSource);
535 static void serializeToString(xercesc::DOMNode *n, std::string &outputData);
537 void resetCachedGrammarPool();
539 std::shared_ptr<xercesc::DOMDocument> createDocument();
540
541 const std::map<FQN, xercesc::XSTypeDefinition*>& getTypeMap() const { return typeMap; }
542 private:
543 xercesc::DOMImplementation *domImpl;
544 DOMParser(const std::variant<boost::filesystem::path, xercesc::DOMElement*> &xmlCatalog);
545 std::shared_ptr<xercesc::DOMLSParser> parser;
546 std::map<FQN, xercesc::XSTypeDefinition*> typeMap;
547 DOMErrorPrinter errorHandler;
548 LocationInfoFilter locationFilter;
549 TypeDerivativeHandler typeDerHandler;
550 EntityResolver entityResolver;
551 std::map<std::string, boost::filesystem::path> registeredGrammar;
552
553 static void handleXInclude(xercesc::DOMElement *&e, std::vector<boost::filesystem::path> *dependencies);
554 };
555
556 }
557
558 namespace {
559
560 template<class T>
561 void CheckSize<T>::check(const xercesc::DOMElement *me, const T &value, int r, int c) {}
562 template<class T>
563 void CheckSize<std::vector<T>>::check(const xercesc::DOMElement *me, const std::vector<T> &value, int r, int c) {
564 if(r!=0 && r!=static_cast<int>(value.size()))
565 throw MBXMLUtils::DOMEvalException("Expected vector of size "+fmatvec::toString(r)+
566 " but got vector of size "+fmatvec::toString(value.size())+".", me);
567 }
568 template<class T>
569 void CheckSize<std::vector<std::vector<T>>>::check(const xercesc::DOMElement *me, const std::vector<std::vector<T>> &value, int r, int c) {
570 if(r!=0 && r!=static_cast<int>(value.size()))
571 throw MBXMLUtils::DOMEvalException("Expected matrix of row-size "+fmatvec::toString(r)+
572 " but got matrix of row-size "+fmatvec::toString(value.size())+".", me);
573 if(!value.empty() && c!=0 && c!=static_cast<int>(value[0].size()))
574 throw MBXMLUtils::DOMEvalException("Expected matrix of col-size "+fmatvec::toString(c)+
575 " but got matrix of col-size "+fmatvec::toString(value[0].size())+".", me);
576 }
577
578 }
579
580 #endif
MBXMLUtils::DOMElementWrapper::getFirstTextChild
const xercesc::DOMText * getFirstTextChild() const
Definition: dom.cc:389
MBXMLUtils::DOMDocumentWrapper::createElement
xercesc::DOMElement * createElement(const FQN &name)
Definition: dom.cc:739
MBXMLUtils::FQN::FQN
FQN()=default
Empty FQN.
MBXMLUtils::FQN::FQN
FQN(const char *name)
Anonymous FQN (required for implicit casting of string literals to anonymous FQNs)
Definition: dom.h:116
MBXMLUtils::DOMElementWrapper::getOriginalElementLineNumber
int getOriginalElementLineNumber() const
Get the line number of the original element.
Definition: dom.cc:643
MBXMLUtils::XercesUniquePtrDeleter
Definition: dom.h:59
MBXMLUtils::DOMElementWrapper::getRootXPathExpression
std::string getRootXPathExpression() const
Definition: dom.cc:581
MBXMLUtils::FQN
Definition: dom.h:109
MBXMLUtils::DOMElementWrapper::getTagName
FQN getTagName() const
Get full qualified tag name.
Definition: dom.h:257
MBXMLUtils::DOMDocumentWrapper::evalRootXPathExpression
xercesc::DOMNode * evalRootXPathExpression(std::string xpathExpression, xercesc::DOMElement *context=nullptr)
Definition: dom.cc:781
MBXMLUtils::DOMElementWrapper::setEmbedCountNumber
void setEmbedCountNumber(int embedCount)
Definition: dom.cc:558
MBXMLUtils::DOMElementWrapper::operator->
std::conditional< std::is_same< DOMElementType, const xercesc::DOMElement >::value, const DOMElementWrapper *, DOMElementWrapper * >::type operator->()
Treat this object as a pointer (like DOMElement*)
Definition: dom.h:379
MBXMLUtils::DOMElementWrapper::getFirstCommentChild
const xercesc::DOMComment * getFirstCommentChild() const
Get first child comment.
Definition: dom.cc:370
MBXMLUtils::NamespaceURI
Helper class to easily construct full qualified XML names (FQN) using XML namespace prefixes.
Definition: dom.h:122
MBXMLUtils::FQN::FQN
FQN(const std::string &ns, const std::string &name)
FQN.
Definition: dom.h:118
MBXMLUtils::DOMElementWrapper::getAttributeNode
const xercesc::DOMAttr * getAttributeNode(const FQN &name) const
Get attribute node named name.
Definition: dom.cc:489
MBXMLUtils::FQN::FQN
FQN(const std::string &name)
Anonymous FQN.
Definition: dom.h:114
MBXMLUtils::EntityResolver
Definition: dom.h:502
MBXMLUtils::LocationInfoFilter
Definition: dom.h:476
MBXMLUtils::DOMElementWrapper::setAttribute
void setAttribute(const FQN &name, const T &value)
Set attribute.
Definition: dom.h:368
MBXMLUtils::DOMAttrWrapper::isDerivedFrom
bool isDerivedFrom(const FQN &baseTypeName) const
Definition: dom.cc:690
MBXMLUtils::X
Definition: dom.h:86
MBXMLUtils::DOMDocumentWrapper
Helper class for extending DOMDocument (use the function D(...)).
Definition: dom.h:65
MBXMLUtils::DOMElementWrapper::DOMElementWrapper
DOMElementWrapper(DOMElementType *me_)
Wrap DOMElement to my special element.
Definition: dom.h:255
MBXMLUtils::DOMElementWrapper::getText
T getText(int r=0, int c=0) const
Get the child text as type T.
Definition: dom.h:292
MBXMLUtils::DOMElementWrapper::setEmbedXPathCount
void setEmbedXPathCount(int xPathCount)
Definition: dom.cc:574
MBXMLUtils::DOMElementWrapper::getEmbedData
std::string getEmbedData(const std::string &name) const
Get the embed data named name from the current element. Returns "" if not such data exists.
Definition: dom.cc:348
MBXMLUtils::DOMDocumentWrapper::validate
XercesUniquePtr< xercesc::DOMElement > validate()
Definition: dom.cc:705
MBXMLUtils::DOMElementWrapper::isDerivedFrom
bool isDerivedFrom(const FQN &baseTypeName) const
Definition: dom.cc:681
MBXMLUtils::DOMElementWrapper::getAttributeQName
FQN getAttributeQName(const FQN &name) const
Get attribute named name of type QName.
Definition: dom.cc:478
MBXMLUtils::DOMElementWrapper::hasAttribute
bool hasAttribute(const FQN &name) const
check if this element has a attibute named name.
Definition: dom.cc:659
MBXMLUtils::DOMDocumentWrapper::locateElement
xercesc::DOMElement * locateElement(const std::vector< int > &idx) const
Definition: dom.cc:821
MBXMLUtils::DOMParser::createDocument
std::shared_ptr< xercesc::DOMDocument > createDocument()
create a empty document
Definition: dom.cc:1302
MBXMLUtils::DOMElementWrapper::getLineNumber
int getLineNumber() const
Definition: dom.cc:535
MBXMLUtils::EmbedDOMLocator
Definition: dom.h:142
MBXMLUtils::InitXerces
Initialize Xerces on load and terminate it on unload of the library/program.
Definition: dom.h:74
MBXMLUtils::DOMElementWrapper::convertPath
boost::filesystem::path convertPath(const boost::filesystem::path &relPath) const
Definition: dom.cc:464
MBXMLUtils::DOMAttrWrapper::getRootXPathExpression
std::string getRootXPathExpression() const
Definition: dom.cc:696
MBXMLUtils::DOMElementWrapper::getNextElementSiblingNamed
const xercesc::DOMElement * getNextElementSiblingNamed(const FQN &name) const
Get next sibling element of the specified full qualified name.
Definition: dom.cc:302
MBXMLUtils::DOMEvalException
Definition: dom.h:186
MBXMLUtils::DOMElementWrapper::getFirstElementChildNamed
const xercesc::DOMElement * getFirstElementChildNamed(const FQN &name) const
Get first child element of the specified full qualified name.
Definition: dom.cc:285
MBXMLUtils::DOMElementWrapper::getElementLocation
std::vector< int > getElementLocation() const
Definition: dom.cc:625
MBXMLUtils::DOMAttrWrapper
Helper class for extending DOMAttr (use the function A(...)).
Definition: dom.h:401
MBXMLUtils::DOMElementWrapper::setOriginalElementLineNumber
void setOriginalElementLineNumber(int lineNr)
Set the line number of the original element.
Definition: dom.cc:652
MBXMLUtils::DOMParser::create
static std::shared_ptr< DOMParser > create(const std::variant< boost::filesystem::path, xercesc::DOMElement * > &xmlCatalog=static_cast< xercesc::DOMElement * >(nullptr))
Definition: dom.cc:1070
MBXMLUtils::DOMEvalException::convertToString
static std::string convertToString(const EmbedDOMLocator &loc, const std::string &message, bool subsequentError=false)
Definition: dom.cc:934
MBXMLUtils::DOMElementWrapper::getOriginalFilename
boost::filesystem::path getOriginalFilename(bool skipThis=false, const xercesc::DOMElement *&found=DOMElementWrapper< DOMElementType >::dummyArg) const
Definition: dom.cc:430
MBXMLUtils::DOMParser::resetCachedGrammarPool
void resetCachedGrammarPool()
reset all loaded grammars
Definition: dom.cc:1297
MBXMLUtils::DOMErrorPrinter
Print DOM error messages.
Definition: dom.h:237
MBXMLUtils::DOMElementWrapper
Helper class for extending DOMElement (use the function E(...)).
Definition: dom.h:69
MBXMLUtils::DOMDocumentWrapper::getDocumentFilename
boost::filesystem::path getDocumentFilename() const
Definition: dom.cc:753
MBXMLUtils::DOMElementWrapper::removeAttribute
void removeAttribute(const FQN &name)
remove from this element the attibute named name.
Definition: dom.cc:544
MBXMLUtils::DOMDocumentWrapper::getParser
std::shared_ptr< DOMParser > getParser() const
Get full qualified tag name.
Definition: dom.cc:747
MBXMLUtils::DOMParser
A XML DOM parser.
Definition: dom.h:511
MBXMLUtils::DOMElementWrapper::getFirstProcessingInstructionChildNamed
const xercesc::DOMProcessingInstruction * getFirstProcessingInstructionChildNamed(const std::string &target) const
Get first child processing instruction of the specified target.
Definition: dom.cc:319
MBXMLUtils::DOMAttrWrapper::operator->
std::conditional< std::is_same< DOMAttrType, const xercesc::DOMAttr >::value, const DOMAttrWrapper *, DOMAttrWrapper * >::type operator->()
Treat this object as a pointer (like DOMAttr*)
Definition: dom.h:413
MBXMLUtils::TypeDerivativeHandler
Definition: dom.h:486
MBXMLUtils::DOMParser::serializeToString
static void serializeToString(xercesc::DOMNode *n, std::string &outputData)
Definition: dom.cc:1273
MBXMLUtils::DOMParser::parse
std::shared_ptr< xercesc::DOMDocument > parse(const boost::filesystem::path &inputSource, std::vector< boost::filesystem::path > *dependencies=nullptr, bool doXInclude=true)
Definition: dom.cc:1192
MBXMLUtils::DOMAttrWrapper::DOMAttrWrapper
DOMAttrWrapper(DOMAttrType *me_)
Wrap DOMAttr to my special element.
Definition: dom.h:404
MBXMLUtils::DOMDocumentWrapper::DOMDocumentWrapper
DOMDocumentWrapper(DOMDocumentType *me_)
Wrap DOMDocument to my special element.
Definition: dom.h:436
MBXMLUtils::DOMElementWrapper::addEmbedData
void addEmbedData(const std::string &name, const std::string &data)
Definition: dom.cc:360
MBXMLUtils::DOMElementWrapper::addProcessingInstructionChildNamed
void addProcessingInstructionChildNamed(const std::string &target, const std::string &data)
Add a processing instruction child of the specified target.
Definition: dom.cc:342
MBXMLUtils::DOMDocumentWrapper::operator->
std::conditional< std::is_same< DOMDocumentType, const xercesc::DOMDocument >::value, const DOMDocumentWrapper *, DOMDocumentWrapper * >::type operator->()
Treat this object as a pointer (like DOMDocument*)
Definition: dom.h:460
MBXMLUtils::DOMElementWrapper::setOriginalFilename
void setOriginalFilename(boost::filesystem::path orgFileName=boost::filesystem::path())
Definition: dom.cc:457
MBXMLUtils::DOMElementWrapper::getEmbedCountNumber
int getEmbedCountNumber() const
Definition: dom.cc:549
MBXMLUtils::UserDataHandler
Definition: dom.h:495
MBXMLUtils::DOMElementWrapper::getEmbedXPathCount
int getEmbedXPathCount() const
Definition: dom.cc:565
MBXMLUtils::DOMParser::serialize
static void serialize(xercesc::DOMNode *n, const boost::filesystem::path &outputSource)
Definition: dom.cc:1252
MBXMLUtils::DOMElementWrapper::getAttribute
std::string getAttribute(const FQN &name) const
Get attribute named name.
Definition: dom.cc:472