40#ifndef DRAIN_UTILS_XML
41#define DRAIN_UTILS_XML
45#include <drain/Sprinter.h>
59 typedef path_t::elem_t path_elem_t;
61 typedef std::list<path_t> path_list_t;
78 bool findById(
const V & tree,
const std::string & tag,
typename V::path_t & result,
const typename V::path_t & path =
path_t());
94 bool findById(
const T & tree,
const std::string & tag, path_list_t & result,
const path_t & path =
path_t());
98 template <
class T,
class E>
108 template <
class T,
class E>
119 template <
class T,
class C>
121 bool findByClass(
const T & t,
const C & cls, std::list<typename T::path_elem_t> & result);
130 template <
class T,
class C>
145bool UtilsXML::findById(
const T & t,
const std::string &
id,
typename T::path_t & result,
const typename T::path_t & path){
153 for (
const auto & entry: t){
154 if (
findById(entry.second,
id, result,
path_t(path, entry.first))){
169 result.push_back(path);
172 for (
const auto & entry: t){
176 return !result.empty();
183template <
class T,
class N>
189 result.push_back(path);
192 for (
const auto & entry: t){
196 return !result.empty();
203template <
class T,
class N>
209 if (tags.count(t->getType()) > 0){
210 result.push_back(path);
213 for (
const auto & entry: t){
218 return !result.empty();
223template <
class T,
class C>
228 if (t->classList.has(cls)){
229 result.push_back(path);
232 for (
const auto & entry: t){
237 return !result.empty();
241template <
class T,
class C>
244 for (
const auto & entry: t){
245 if (entry.second->hasClass(cls)){
246 result.push_back(entry.first);
250 return !result.empty();
387 for (const auto & entry: children){
388 toStream(ostr, entry.second, entry.first, indent+1); // Notice, no ++indent
389 // "implicit" newline
391 ostr << fill; // for CLOSING tag
397 tree->nodeToStream(ostr, CLOSING_TAG);
399 ostr << '\n'; // Always after closing tag!
401 //if (tree.data.id >= 0)
402 // ostr << "<!-- " << tree.data.id << " /-->\n";
static bool findByTag(const T &tree, const E &tag, path_list_t &result, const path_t &path=path_t())
static bool findByClass(const T &t, const C &cls, std::list< typename T::path_elem_t > &result)
Finds child elements in an XML structure by class name.
Definition UtilsXML.h:242
static bool findByTags(const T &tree, const std::set< E > &tags, path_list_t &result, const path_t &path=path_t())
"Forward definition"
static bool findById(const V &tree, const std::string &tag, typename V::path_t &result, const typename V::path_t &path=path_t())
Find the first occurrence of given id using recursive breath-first search.
drain::Path< std::string,'/'> path_t
Tree path type. // TODO: extract from template.
Definition UtilsXML.h:58
Definition DataSelector.cpp:1277