mbxmlutils  1.3.0
Multi-Body XML Utils
dom.h
1#ifndef _MBXMLUTILSHELPER_DOM_H_
2#define _MBXMLUTILSHELPER_DOM_H_
3
4#include <boost/algorithm/string/trim.hpp>
5#include <fmatvec/atom.h>
6#include <string>
7#include <utility>
8#include <vector>
9#include <map>
10#include <set>
11#include <variant>
12#include <boost/filesystem.hpp>
13#include <xercesc/dom/DOMErrorHandler.hpp>
14#include <xercesc/dom/DOMElement.hpp>
15#include <xercesc/dom/DOMText.hpp>
16#include <xercesc/dom/DOMLSParser.hpp>
17#include <xercesc/dom/DOMLocator.hpp>
18#include <xercesc/dom/DOMUserDataHandler.hpp>
19#include <xercesc/dom/DOMDocument.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 <boost/functional/hash.hpp>
25#include <fmatvec/toString.h>
26#include "simdutf.h"
27
28namespace XERCES_CPP_NAMESPACE {
29 class DOMProcessingInstruction;
30 class DOMImplementation;
31 class AbstractDOMParser;
32}
33
34namespace boost {
35 template<> std::vector<double> lexical_cast(const std::string& str);
36 template<> std::vector<std::vector<double>> lexical_cast(const std::string& str);
37 template<> std::vector<int> lexical_cast(const std::string& str);
38 template<> std::vector<std::vector<int>> lexical_cast(const std::string& str);
39 template<> bool lexical_cast<bool>(const std::string& arg);
40}
41
42namespace {
43
44template<class T>
45struct CheckSize {
46 static void check(const xercesc::DOMElement *me, const T &value, int r, int c);
47};
48template<class T>
49struct CheckSize<std::vector<T>> {
50 static void check(const xercesc::DOMElement *me, const std::vector<T> &value, int r, int c);
51};
52template<class T>
53struct CheckSize<std::vector<std::vector<T>>> {
54 static void check(const xercesc::DOMElement *me, const std::vector<std::vector<T>> &value, int r, int c);
55};
56
57}
58
59namespace MBXMLUtils {
60
61template<class T> struct XercesUniquePtrDeleter { void operator()(T *n) { if(n) n->release(); } };
63template<class T> using XercesUniquePtr = std::unique_ptr<T, XercesUniquePtrDeleter<T>>;
64
65// forward declaration
66template<typename DOMDocumentType>
68template<typename DOMDocumentType>
69DOMDocumentWrapper<DOMDocumentType> D(DOMDocumentType *me);
70template<typename DOMElementType>
72template<typename DOMElementType>
73DOMElementWrapper<DOMElementType> E(DOMElementType *me);
74
77 public:
78 InitXerces() {
79 xercesc::XMLPlatformUtils::Initialize();
80 }
81 ~InitXerces() {
82 xercesc::XMLPlatformUtils::Terminate();
83 }
84};
85
88class X {
89 public:
90 const XMLCh *operator%(const std::string &in) {
91 auto &out = store.emplace_back(in.size()*2+1); // utf16 is at most 2 words per character plus 1 null at the end
92 auto outSize = simdutf::convert_valid_utf8_to_utf16(in.data(), in.size(), out.data());
93 out[outSize] = 0; // set null at the end, the rest of the memory is skipped
94 return out.data();
95 }
96 const XMLCh *operator()(const std::string &in) { return operator%(in); }
97 std::string operator%(const XMLCh *in) {
98 if(!in || in[0]==0)
99 return {};
100 auto inSize = std::char_traits<char16_t>::length(in);
101 std::string out(inSize*4, 0); // utf8 is at most 4 bytes per character
102 auto outSize = simdutf::convert_valid_utf16_to_utf8(in, inSize, out.data());
103 out.resize(outSize); // now shrink out to the real size
104 return out;
105 }
106 std::string operator()(const XMLCh *in) { return operator%(in); }
107 private:
108 // store 1 string of at most 100 characters on the stack -> more/larger string are stored on the heap
109 boost::container::small_vector<boost::container::small_vector<char16_t, 100*2+1>, 1> store;
110};
111
114class FQN : public std::pair<std::string, std::string> {
115 public:
117 FQN() = default;
119 FQN(const std::string &name) : std::pair<std::string, std::string>("", name) {}
121 FQN(const char *name) : std::pair<std::string, std::string>("", name) {}
123 FQN(const std::string &ns, const std::string &name) : std::pair<std::string, std::string>(ns, name) {}
124};
125
128class EmbedDOMLocator : public xercesc::DOMLocator {
129 public:
130 EmbedDOMLocator(const boost::filesystem::path &file_, int row_, int embedCount_, std::string xpath_) : DOMLocator(),
131 file(x%file_.string()), row(row_), embedCount(embedCount_), xpath(std::move(xpath_)) {}
132 EmbedDOMLocator(const EmbedDOMLocator &src) : DOMLocator(),
133 file(x%(X()%src.file)), row(src.row), embedCount(src.embedCount), xpath(src.xpath) {}
134 EmbedDOMLocator& operator=(const EmbedDOMLocator &src) {
135 file=x%(X()%src.file);
136 row=src.row;
137 embedCount=src.embedCount;
138 xpath=src.xpath;
139 return *this;
140 }
141 ~EmbedDOMLocator() override = default;
142 EmbedDOMLocator(const EmbedDOMLocator &&src) = delete;
143 EmbedDOMLocator& operator=(const EmbedDOMLocator &&src) = delete;
144 XMLFileLoc getLineNumber() const override { return row; }
145 XMLFileLoc getColumnNumber() const override { return 0; }
146 XMLFilePos getByteOffset() const override { return ~(XMLFilePos(0)); }
147 XMLFilePos getUtf16Offset() const override { return ~(XMLFilePos(0)); }
148 xercesc::DOMNode *getRelatedNode() const override { return nullptr; }
149 const XMLCh *getURI() const override { return file; }
150 int getEmbedCount() const { return embedCount; }
152 const std::string& getRootXPathExpression() const { return xpath; }
154 static std::string convertToRootHRXPathExpression(const std::string &xpath);
155 static void addNSURIPrefix(std::string nsuri, const std::vector<std::string> &prefix);
156 static const std::map<std::string, std::string>& getNSURIPrefix() { return nsURIPrefix(); }
157 private:
158 X x;
159 const XMLCh *file;
160 int row;
161 int embedCount;
162 std::string xpath;
163 static std::map<std::string, std::string>& nsURIPrefix();
164};
165
168 public:
169 NamespaceURI(std::string nsuri_, const std::vector<std::string> &preferredPrefix={}) : nsuri(std::move(nsuri_)) {
170 EmbedDOMLocator::addNSURIPrefix(nsuri, preferredPrefix);
171 }
172 FQN operator%(const std::string &localName) const { return {nsuri, localName}; }
173 const std::string& getNamespaceURI() const { return nsuri; }
174 private:
175 std::string nsuri;
176};
177
179const NamespaceURI XINCLUDE("http://www.w3.org/2001/XInclude", {"xi", "xinc", "xinclude"});
181const NamespaceURI XMLNS("http://www.w3.org/2000/xmlns/", {"xmlns"});
183const NamespaceURI PV("http://www.mbsim-env.de/MBXMLUtils", {"p", "pv", "mbxmlutils"});
185const NamespaceURI XMLCATALOG("urn:oasis:names:tc:entity:xmlns:xml:catalog", {"catalog", "xmlcatalog"});
186
187// Exception wrapping for DOMEvalException.
188// Rethrow a exception as DOMEvalException with context e, a DOMEvalException is just rethrown unchanged.
189#define RETHROW_AS_DOMEVALEXCEPTION(e) \
190 catch(MBXMLUtils::DOMEvalException &ex) { \
191 throw; \
192 } \
193 catch(const std::exception &ex) { \
194 throw DOMEvalException(ex.what(), e); \
195 }
196
199class DOMEvalException : public std::exception {
200 friend class DOMParser;
201 friend class DOMErrorPrinter;
202 public:
203 DOMEvalException() = default;
204 DOMEvalException(const std::string &errorMsg_, const xercesc::DOMNode *n);
205 void appendContext(const xercesc::DOMNode *n, int lineNr=0);
206 const std::string& getMessage() const { return errorMsg; }
207 void setMessage(const std::string& errorMsg_) { errorMsg=errorMsg_; }
208 void setSubsequentError(bool sse) { subsequentError=sse; }
209 const char* what() const noexcept override;
210 xercesc::DOMNode::NodeType getNodeType() const { return nodeType; }
211 static bool isHTMLOutputEnabled();
212 static void htmlEscaping(std::string &msg);
213 protected:
214 DOMEvalException(const std::string &errorMsg_, const xercesc::DOMLocator &loc);
215 private:
252 static std::string convertToString(const EmbedDOMLocator &loc, const std::string &message, bool subsequentError=false);
253
254 bool subsequentError{false};
255 std::string errorMsg;
256 std::vector<EmbedDOMLocator> locationStack;
257 mutable std::string whatStr;
258 xercesc::DOMNode::NodeType nodeType { static_cast<xercesc::DOMNode::NodeType>(-1) };
259};
260
262class DOMErrorPrinter: public xercesc::DOMErrorHandler, virtual public fmatvec::Atom
263{
264 public:
265 DOMErrorPrinter() = default;
266 bool handleError(const xercesc::DOMError&) override;
267 bool hasError() { return errorSet; }
268 const DOMEvalException& getError() { return error; }
269 void resetError() { errorSet=false; }
270 private:
271 bool errorSet{false};
272 DOMEvalException error;
273};
274
276template<typename DOMElementType>
278 public:
280 DOMElementWrapper(DOMElementType *me_) : me(me_) {}
282 FQN getTagName() const { return FQN(X()%me->getNamespaceURI(), X()%me->getLocalName()); }
284 const xercesc::DOMElement *getFirstElementChildNamed(const FQN &name) const;
286 xercesc::DOMElement *getFirstElementChildNamed(const FQN &name);
288 const xercesc::DOMElement *getNextElementSiblingNamed(const FQN &name) const;
290 xercesc::DOMElement *getNextElementSiblingNamed(const FQN &name);
292 const xercesc::DOMProcessingInstruction *getFirstProcessingInstructionChildNamed(const std::string &target) const;
294 xercesc::DOMProcessingInstruction *getFirstProcessingInstructionChildNamed(const std::string &target);
296 void addProcessingInstructionChildNamed(const std::string &target, const std::string &data);
298 std::string getEmbedData(const std::string &name) const;
301 void addEmbedData(const std::string &name, const std::string &data);
303 const xercesc::DOMComment *getFirstCommentChild() const;
305 xercesc::DOMComment *getFirstCommentChild();
310 const xercesc::DOMText *getFirstTextChild() const;
315 xercesc::DOMText *getFirstTextChild();
317 template<class T> T getText(int r=0, int c=0) const {
318 try {
319 auto textEle=E(me)->getFirstTextChild();
320 if(!textEle) {
321 if constexpr(std::is_same_v<T, std::string>) {
322 for(auto *n=me->getFirstChild(); n; n=n->getNextSibling())
323 if(n->getNodeType()==xercesc_3_2::DOMNode::TEXT_NODE || n->getNodeType()==xercesc_3_2::DOMNode::CDATA_SECTION_NODE)
324 if(!boost::trim_copy(X()%static_cast<xercesc::DOMText*>(n)->getData()).empty())
325 throw std::runtime_error("There must be no or a single, none empty, text node but the text node is split by a comment or processing-instruction node.");
326 return "";
327 }
328 else
329 throw std::runtime_error("There must be a single, none empty, text node but either, no text node exists at all, or the text node is split by a comment or processing-instruction node.");
330 }
331 auto text=X()%textEle->getData();
332 if constexpr(!std::is_same_v<T, std::string>)
333 boost::trim(text); // do not trim whitespaces for a string but for anything else
334 auto ret=boost::lexical_cast<T>(text);
335 CheckSize<T>::check(me, ret, r, c);
336 return ret;
337 }
338 catch(const boost::bad_lexical_cast &ex) {
339 throw DOMEvalException(ex.what(), me);
340 }
341 catch(const std::exception &ex) {
342 throw DOMEvalException(ex.what(), me);
343 }
344 }
345
346 template<class T> void addElementText(const FQN &name, const T &value) {
347 xercesc::DOMElement *ele=D(me->getOwnerDocument())->createElement(name);
348 ele->insertBefore(me->getOwnerDocument()->createTextNode(MBXMLUtils::X()%fmatvec::toString(value)), nullptr);
349 me->insertBefore(ele, nullptr);
350 }
353 bool isDerivedFrom(const FQN &baseTypeName) const;
359 boost::filesystem::path getOriginalFilename(bool skipThis=false,
360 const xercesc::DOMElement *&found=DOMElementWrapper<DOMElementType>::dummyArg) const;
365 void setOriginalFilename(boost::filesystem::path orgFileName=boost::filesystem::path());
368 boost::filesystem::path convertPath(const boost::filesystem::path &relPath) const;
371 int getLineNumber() const;
374 int getEmbedCountNumber() const;
377 void setEmbedCountNumber(int embedCount);
380 int getEmbedXPathCount() const;
383 void setEmbedXPathCount(int xPathCount);
388 std::string getRootXPathExpression() const;
391 std::vector<int> getElementLocation() const;
395 void setOriginalElementLineNumber(int lineNr);
397 std::string getAttribute(const FQN &name) const;
399 FQN getAttributeQName(const FQN &name) const;
401 const xercesc::DOMAttr* getAttributeNode(const FQN &name) const;
403 xercesc::DOMAttr* getAttributeNode(const FQN &name);
405 template<class T>
406 void setAttribute(const FQN &name, const T &value) {
407 me->setAttributeNS(X()%name.first, X()%name.second, X()%fmatvec::toString(value));
408 }
410 void setAttribute(const FQN &name, const FQN &value);
412 bool hasAttribute(const FQN &name) const;
414 void removeAttribute(const FQN &name);
416 typename std::conditional<std::is_same<DOMElementType, const xercesc::DOMElement>::value,
418 return this;
419 }
420 static const xercesc::DOMElement *dummyArg;
421 private:
422 DOMElementType *me;
423};
425template<typename DOMElementType>
426DOMElementWrapper<DOMElementType> E(DOMElementType *me) { return DOMElementWrapper<DOMElementType>(me); }
428template<typename DOMElementType>
429DOMElementWrapper<DOMElementType> E(const std::shared_ptr<DOMElementType> &me) { return DOMElementWrapper<DOMElementType>(me.get()); }
431template<typename DOMElementType>
432DOMElementWrapper<DOMElementType> E(const XercesUniquePtr<DOMElementType> &me) { return DOMElementWrapper<DOMElementType>(me.get()); }
433
434template<> const xercesc::DOMElement *DOMElementWrapper< xercesc::DOMElement>::dummyArg;
435template<> const xercesc::DOMElement *DOMElementWrapper<const xercesc::DOMElement>::dummyArg;
436
438template<typename DOMAttrType>
440 public:
442 DOMAttrWrapper(DOMAttrType *me_) : me(me_) {}
445 bool isDerivedFrom(const FQN &baseTypeName) const;
448 std::string getRootXPathExpression() const;
450 typename std::conditional<std::is_same<DOMAttrType, const xercesc::DOMAttr>::value,
452 return this;
453 }
454 private:
455 DOMAttrType *me;
456};
458template<typename DOMAttrType>
459DOMAttrWrapper<DOMAttrType> A(DOMAttrType *me) { return DOMAttrWrapper<DOMAttrType>(me); }
461template<typename DOMAttrType>
462DOMAttrWrapper<DOMAttrType> A(const std::shared_ptr<DOMAttrType> &me) { return DOMAttrWrapper<DOMAttrType>(me.get()); }
464template<typename DOMAttrType>
465DOMAttrWrapper<DOMAttrType> A(const XercesUniquePtr<DOMAttrType> &me) { return DOMAttrWrapper<DOMAttrType>(me.get()); }
466
467class DOMParser;
468
470template<typename DOMDocumentType>
472 public:
474 DOMDocumentWrapper(DOMDocumentType *me_) : me(me_) {}
479 XercesUniquePtr<xercesc::DOMElement> validate();
482 xercesc::DOMElement* createElement(const FQN &name);
484 std::shared_ptr<DOMParser> getParser() const;
487 boost::filesystem::path getDocumentFilename() const;
492 xercesc::DOMNode* evalRootXPathExpression(std::string xpathExpression, xercesc::DOMElement* context=nullptr);
495 xercesc::DOMElement* locateElement(const std::vector<int> &idx) const;
497 typename std::conditional<std::is_same<DOMDocumentType, const xercesc::DOMDocument>::value,
499 return this;
500 }
501 private:
502 DOMDocumentType *me;
503};
505template<typename DOMDocumentType>
506DOMDocumentWrapper<DOMDocumentType> D(DOMDocumentType *me) { return DOMDocumentWrapper<DOMDocumentType>(me); }
508template<typename DOMDocumentType>
509DOMDocumentWrapper<DOMDocumentType> D(const std::shared_ptr<DOMDocumentType> &me) { return DOMDocumentWrapper<DOMDocumentType>(me.get()); }
511template<typename DOMDocumentType>
512DOMDocumentWrapper<DOMDocumentType> D(const XercesUniquePtr<DOMDocumentType> &me) { return DOMDocumentWrapper<DOMDocumentType>(me.get()); }
513
514class LocationInfoFilter : public xercesc::DOMLSParserFilter {
515 public:
516 void setParser(DOMParser *parser_) { parser=parser_; }
517 xercesc::DOMLSParserFilter::FilterAction acceptNode(xercesc::DOMNode *n) override;
518 xercesc::DOMLSParserFilter::FilterAction startElement(xercesc::DOMElement *e) override;
519 xercesc::DOMNodeFilter::ShowType getWhatToShow() const override;
520 void setLineNumberOffset(int offset) { lineNumberOffset=offset; }
521 private:
522 DOMParser *parser;
523 int lineNumberOffset { 0 };
524};
525
526class TypeDerivativeHandler : public xercesc::PSVIHandler, virtual public fmatvec::Atom {
527 public:
528 void setParser(DOMParser *parser_) { parser=parser_; }
529 void handleElementPSVI(const XMLCh *localName, const XMLCh *uri, xercesc::PSVIElement *info) override;
530 void handleAttributesPSVI(const XMLCh *localName, const XMLCh *uri, xercesc::PSVIAttributeList *psviAttributes) override;
531 private:
532 DOMParser *parser;
533};
534
535class UserDataHandler : public xercesc::DOMUserDataHandler {
536 public:
537 void handle(DOMOperationType operation, const XMLCh* key, void *data, const xercesc::DOMNode *src, xercesc::DOMNode *dst) override;
538};
539
540extern UserDataHandler userDataHandler;
541
542class EntityResolver : public xercesc::XMLEntityResolver {
543 public:
544 void setParser(DOMParser *parser_) { parser=parser_; }
545 xercesc::InputSource* resolveEntity(xercesc::XMLResourceIdentifier *resourceIdentifier) override;
546 private:
547 DOMParser *parser;
548};
549
551class DOMParser : public std::enable_shared_from_this<DOMParser> {
552 friend class TypeDerivativeHandler;
553 friend class LocationInfoFilter;
554 friend class UserDataHandler;
555 friend class EntityResolver;
556 friend class DOMElementWrapper<xercesc::DOMElement>;
557 friend class DOMElementWrapper<const xercesc::DOMElement>;
558 template<typename> friend class DOMDocumentWrapper;
559 public:
563 static std::shared_ptr<DOMParser> create(const std::variant<boost::filesystem::path, xercesc::DOMElement*> &xmlCatalog=static_cast<xercesc::DOMElement*>(nullptr));
567 std::shared_ptr<xercesc::DOMDocument> parse(const boost::filesystem::path &inputSource,
568 std::vector<boost::filesystem::path> *dependencies=nullptr,
569 bool doXInclude=true);
573 std::shared_ptr<xercesc::DOMDocument> parse(std::istream &inputStream,
574 std::vector<boost::filesystem::path> *dependencies=nullptr,
575 bool doXInclude=true, const boost::filesystem::path& filename={});
579 xercesc::DOMElement* parseWithContext(const std::string &str, xercesc::DOMNode *contextNode, xercesc::DOMLSParser::ActionType action,
580 std::vector<boost::filesystem::path> *dependencies=nullptr,
581 bool doXInclude=true);
586 static void serialize(xercesc::DOMNode *n, const boost::filesystem::path &outputSource, bool plain=false);
591 static void serializeToString(xercesc::DOMNode *n, std::string &outputData, bool plain=false);
595 std::shared_ptr<xercesc::DOMDocument> createDocument();
596
597 const std::unordered_map<FQN, xercesc::XSTypeDefinition*, boost::hash<FQN>>& getTypeMap() const { return typeMap; }
598 private:
599 xercesc::DOMImplementation *domImpl;
600 DOMParser(const std::variant<boost::filesystem::path, xercesc::DOMElement*> &xmlCatalog);
601 std::shared_ptr<xercesc::DOMLSParser> parser;
602 std::unordered_map<FQN, xercesc::XSTypeDefinition*, boost::hash<FQN>> typeMap;
603 DOMErrorPrinter errorHandler;
604 LocationInfoFilter locationFilter;
605 TypeDerivativeHandler typeDerHandler;
606 EntityResolver entityResolver;
607 std::map<std::string, boost::filesystem::path> registeredGrammar;
608
609 static void handleXInclude(xercesc::DOMElement *&e, std::vector<boost::filesystem::path> *dependencies);
610};
611
612}
613
614namespace {
615
616template<class T>
617void CheckSize<T>::check(const xercesc::DOMElement *me, const T &value, int r, int c) {}
618template<class T>
619void CheckSize<std::vector<T>>::check(const xercesc::DOMElement *me, const std::vector<T> &value, int r, int c) {
620 if(r!=0 && r!=static_cast<int>(value.size()))
621 throw MBXMLUtils::DOMEvalException("Expected vector of size "+fmatvec::toString(r)+
622 " but got vector of size "+fmatvec::toString(value.size())+".", me);
623}
624template<class T>
625void CheckSize<std::vector<std::vector<T>>>::check(const xercesc::DOMElement *me, const std::vector<std::vector<T>> &value, int r, int c) {
626 if(r!=0 && r!=static_cast<int>(value.size()))
627 throw MBXMLUtils::DOMEvalException("Expected matrix of row-size "+fmatvec::toString(r)+
628 " but got matrix of row-size "+fmatvec::toString(value.size())+".", me);
629 if(!value.empty() && c!=0 && c!=static_cast<int>(value[0].size()))
630 throw MBXMLUtils::DOMEvalException("Expected matrix of col-size "+fmatvec::toString(c)+
631 " but got matrix of col-size "+fmatvec::toString(value[0].size())+".", me);
632}
633
634}
635
636#endif
Helper class for extending DOMAttr (use the function A(...)).
Definition: dom.h:439
DOMAttrWrapper(DOMAttrType *me_)
Wrap DOMAttr to my special element.
Definition: dom.h:442
std::string getRootXPathExpression() const
Definition: dom.cc:758
bool isDerivedFrom(const FQN &baseTypeName) const
Definition: dom.cc:752
std::conditional< std::is_same< DOMAttrType, constxercesc::DOMAttr >::value, constDOMAttrWrapper *, DOMAttrWrapper * >::type operator->()
Treat this object as a pointer (like DOMAttr*)
Definition: dom.h:451
Helper class for extending DOMDocument (use the function D(...)).
Definition: dom.h:471
xercesc::DOMElement * locateElement(const std::vector< int > &idx) const
Definition: dom.cc:890
boost::filesystem::path getDocumentFilename() const
Definition: dom.cc:823
xercesc::DOMElement * createElement(const FQN &name)
Definition: dom.cc:809
DOMDocumentWrapper(DOMDocumentType *me_)
Wrap DOMDocument to my special element.
Definition: dom.h:474
std::conditional< std::is_same< DOMDocumentType, constxercesc::DOMDocument >::value, constDOMDocumentWrapper *, DOMDocumentWrapper * >::type operator->()
Treat this object as a pointer (like DOMDocument*)
Definition: dom.h:498
xercesc::DOMNode * evalRootXPathExpression(std::string xpathExpression, xercesc::DOMElement *context=nullptr)
Definition: dom.cc:850
XercesUniquePtr< xercesc::DOMElement > validate()
Definition: dom.cc:774
std::shared_ptr< DOMParser > getParser() const
Get full qualified tag name.
Definition: dom.cc:817
Helper class for extending DOMElement (use the function E(...)).
Definition: dom.h:277
void setOriginalElementLineNumber(int lineNr)
Set the line number of the original element.
Definition: dom.cc:714
std::string getRootXPathExpression() const
Definition: dom.cc:639
void setEmbedCountNumber(int embedCount)
Definition: dom.cc:616
std::conditional< std::is_same< DOMElementType, constxercesc::DOMElement >::value, constDOMElementWrapper *, DOMElementWrapper * >::type operator->()
Treat this object as a pointer (like DOMElement*)
Definition: dom.h:417
std::string getAttribute(const FQN &name) const
Get attribute named name.
Definition: dom.cc:530
const xercesc::DOMComment * getFirstCommentChild() const
Get first child comment.
Definition: dom.cc:428
bool hasAttribute(const FQN &name) const
check if this element has a attibute named name.
Definition: dom.cc:721
const xercesc::DOMProcessingInstruction * getFirstProcessingInstructionChildNamed(const std::string &target) const
Get first child processing instruction of the specified target.
Definition: dom.cc:377
const xercesc::DOMText * getFirstTextChild() const
Definition: dom.cc:447
boost::filesystem::path getOriginalFilename(bool skipThis=false, const xercesc::DOMElement *&found=DOMElementWrapper< DOMElementType >::dummyArg) const
Definition: dom.cc:488
int getEmbedCountNumber() const
Definition: dom.cc:607
std::vector< int > getElementLocation() const
Definition: dom.cc:687
FQN getAttributeQName(const FQN &name) const
Get attribute named name of type QName.
Definition: dom.cc:536
void addProcessingInstructionChildNamed(const std::string &target, const std::string &data)
Add a processing instruction child of the specified target.
Definition: dom.cc:400
const xercesc::DOMAttr * getAttributeNode(const FQN &name) const
Get attribute node named name.
Definition: dom.cc:547
const xercesc::DOMElement * getNextElementSiblingNamed(const FQN &name) const
Get next sibling element of the specified full qualified name.
Definition: dom.cc:360
void removeAttribute(const FQN &name)
remove from this element the attibute named name.
Definition: dom.cc:602
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:406
boost::filesystem::path convertPath(const boost::filesystem::path &relPath) const
Definition: dom.cc:522
T getText(int r=0, int c=0) const
Get the child text as type T.
Definition: dom.h:317
void setEmbedXPathCount(int xPathCount)
Definition: dom.cc:632
const xercesc::DOMElement * getFirstElementChildNamed(const FQN &name) const
Get first child element of the specified full qualified name.
Definition: dom.cc:343
bool isDerivedFrom(const FQN &baseTypeName) const
Definition: dom.cc:743
void setOriginalFilename(boost::filesystem::path orgFileName=boost::filesystem::path())
Definition: dom.cc:515
void setAttribute(const FQN &name, const T &value)
Set attribute.
Definition: dom.h:406
FQN getTagName() const
Get full qualified tag name.
Definition: dom.h:282
int getOriginalElementLineNumber() const
Get the line number of the original element.
Definition: dom.cc:705
DOMElementWrapper(DOMElementType *me_)
Wrap DOMElement to my special element.
Definition: dom.h:280
void addEmbedData(const std::string &name, const std::string &data)
Definition: dom.cc:418
int getEmbedXPathCount() const
Definition: dom.cc:623
int getLineNumber() const
Definition: dom.cc:593
Print DOM error messages.
Definition: dom.h:263
Definition: dom.h:199
static std::string convertToString(const EmbedDOMLocator &loc, const std::string &message, bool subsequentError=false)
Definition: dom.cc:1040
A XML DOM parser.
Definition: dom.h:551
std::shared_ptr< xercesc::DOMDocument > createDocument()
create a empty document
Definition: dom.cc:1519
xercesc::DOMElement * parseWithContext(const std::string &str, xercesc::DOMNode *contextNode, xercesc::DOMLSParser::ActionType action, std::vector< boost::filesystem::path > *dependencies=nullptr, bool doXInclude=true)
Definition: dom.cc:1408
static void serialize(xercesc::DOMNode *n, const boost::filesystem::path &outputSource, bool plain=false)
Definition: dom.cc:1473
static void serializeToString(xercesc::DOMNode *n, std::string &outputData, bool plain=false)
Definition: dom.cc:1485
std::shared_ptr< xercesc::DOMDocument > parse(const boost::filesystem::path &inputSource, std::vector< boost::filesystem::path > *dependencies=nullptr, bool doXInclude=true)
void resetCachedGrammarPool()
reset all loaded grammars
Definition: dom.cc:1514
static std::shared_ptr< DOMParser > create(const std::variant< boost::filesystem::path, xercesc::DOMElement * > &xmlCatalog=static_cast< xercesc::DOMElement * >(nullptr))
Definition: dom.cc:1213
Definition: dom.h:128
static std::string convertToRootHRXPathExpression(const std::string &xpath)
get human readable (simple) XPath expression to the location
Definition: dom.cc:302
const std::string & getRootXPathExpression() const
get a (simple) XPath expression to the location: each element is prefixed with the namespace URI betw...
Definition: dom.h:152
Definition: dom.h:542
Definition: dom.h:114
FQN(const char *name)
Anonymous FQN (required for implicit casting of string literals to anonymous FQNs)
Definition: dom.h:121
FQN(const std::string &ns, const std::string &name)
FQN.
Definition: dom.h:123
FQN()=default
Empty FQN.
FQN(const std::string &name)
Anonymous FQN.
Definition: dom.h:119
Initialize Xerces on load and terminate it on unload of the library/program.
Definition: dom.h:76
Definition: dom.h:514
Helper class to easily construct full qualified XML names (FQN) using XML namespace prefixes.
Definition: dom.h:167
Definition: dom.h:535
Definition: dom.h:88