9#include <Poco/DOM/DOMParser.h>
10#include <boost/algorithm/string/trim.hpp>
12#include <Poco/DOM/NamedNodeMap.h>
14#include <Poco/DOM/NodeFilter.h>
15#include <Poco/DOM/NodeIterator.h>
16#include <Poco/DOM/NodeList.h>
18#include <Poco/SAX/InputSource.h>
26 std::ifstream in(filename);
27 Poco::XML::InputSource src(in);
28 Poco::XML::DOMParser parser;
29 pDoc = parser.parse(&src);
38 std::map<std::string, std::string> metadata;
40 Poco::XML::NodeIterator it(
pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
41 Poco::XML::Node *pNode = it.nextNode();
44 Poco::AutoPtr<Poco::XML::NodeList> children = pNode->childNodes();
45 if (children->length() == 1 && std::find(std::begin(tags_to_ignore), std::end(tags_to_ignore), pNode->nodeName()) ==
46 std::end(tags_to_ignore)) {
47 std::string key = pNode->parentNode()->nodeName() +
"/" + pNode->nodeName();
48 std::string
value = pNode->innerText();
49 boost::algorithm::trim(
value);
50 metadata.emplace(key,
value);
52 pNode = it.nextNode();
58 Poco::XML::NodeIterator it(
pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
59 Poco::XML::Node *pNode = it.nextNode();
60 Poco::XML::Node *detectorNode = pNode->getNodeByPath(xpath);
63 value = detectorNode->innerText();
68 std::map<std::string, std::string> attributes_map;
69 Poco::XML::NodeIterator it(
pDoc, Poco::XML::NodeFilter::SHOW_ELEMENT);
70 Poco::XML::Node *pNode = it.nextNode();
71 Poco::XML::Node *detectorNode = pNode->getNodeByPath(xpath);
73 Poco::AutoPtr<Poco::XML::NamedNodeMap> attributes = detectorNode->attributes();
74 for (
unsigned int i = 0; i < attributes->length(); i++) {
75 Poco::XML::Node *attribute = attributes->item(i);
76 attributes_map.emplace(attribute->nodeName(), attribute->nodeValue());
79 return attributes_map;
89 std::vector<std::string> subnodes;
90 Poco::XML::Node *xpathNode =
pDoc->getNodeByPath(xpath);
92 Poco::XML::NodeIterator it(xpathNode, Poco::XML::NodeFilter::SHOW_ELEMENT);
93 Poco::XML::Node *pNode = it.nextNode();
96 Poco::AutoPtr<Poco::XML::NodeList> children = pNode->childNodes();
97 if (children->length() == 1) {
98 subnodes.emplace_back(pNode->nodeName());
100 pNode = it.nextNode();
double value
The value of the point.
Poco::AutoPtr< Poco::XML::Document > pDoc
std::string get_text_from_tag(const std::string &)
std::map< std::string, std::string > get_metadata(const std::vector< std::string > &tags_to_ignore)
Build dictionary {string : string } of all tags in the dictionary Composed tags: / replaced by _.
std::map< std::string, std::string > get_attributes_from_tag(const std::string &)
std::vector< std::string > get_subnodes(const std::string &)
Returns list of sub-nodes for a xpath node For: xpath = //Data/ Returns: Detector ,...