37 #ifndef _XML_ELEMENT_HPP_
38 # define _XML_ELEMENT_HPP_
44 using Str2Chr = std::map<std::string, unsigned char>;
74 using XmlSet = std::set<const XmlElement *, EntityOrderComp>;
75 using XmlAttrs = std::map<std::string, std::string>;
85 using XmlSubEls = std::multimap<std::string, XmlElement *>;
102 F8API XmlElement(std::istream& ifs,
int subidx,
XmlElement *parent=
nullptr,
int txtline=0,
int depth=0,
const char *rootAttr=
nullptr);
125 const std::string *atag=
nullptr,
const std::string *aval=
nullptr,
const char delim=
'/')
const;
135 const std::string *atag=
nullptr,
const std::string *aval=
nullptr,
const char delim=
'/')
const;
145 const std::string *atag=
nullptr,
const std::string *aval=
nullptr,
const char delim=
'/')
const
147 const std::string sterm(tag_ +
'/' + what);
148 return find(sterm, atag, aval, delim);
160 const std::string *atag=
nullptr,
const std::string *aval=
nullptr,
const char delim=
'/')
const
162 const std::string sterm(tag_ +
'/' + what);
163 return find(sterm, eset, atag, aval, delim);
170 F8API bool GetAttr(
const std::string& what, std::string& target)
const;
177 static const std::string valstr(
"value");
178 return GetAttr(valstr, target);
185 {
return attrs_ ? attrs_->find(what) != attrs_->end() :
false; }
209 T
FindAttr(
const std::string& what,
const T defValue)
const
213 XmlAttrs::iterator itr(attrs_->find(what));
214 if (itr != attrs_->end())
215 return FIX8::get_value<T>(itr->second);
231 XmlAttrs::iterator itr(attrs_->find(what));
232 if (itr != attrs_->end())
233 target = FIX8::get_value<T>(itr->second);
298 std::ostringstream ostr;
299 ostr <<
'"' << tag_ <<
"\" (" <<
GetPath() <<
':' << txtline_ <<
')';
324 XmlAttrs::const_iterator
abegin()
const {
return attrs_ ? attrs_->begin() : emptyattrs_.end(); }
328 XmlAttrs::const_iterator
aend()
const {
return attrs_ ? attrs_->end() : emptyattrs_.end(); }
332 XmlSet::const_iterator
begin()
const {
return ordchildren_ ? ordchildren_->begin() : emptyset_.end(); }
336 XmlSet::const_iterator
end()
const {
return ordchildren_ ? ordchildren_->end() : emptyset_.end(); }
355 #endif // _XML_ELEMENT_HPP_
static F8API XmlElement * Factory(std::istream &istr, const char *docpath=nullptr)
F8API const XmlElement * find_child(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
F8API std::ostream & operator<<(std::ostream &os, const XmlElement &en)
T FindAttr(const std::string &what, const T defValue) const
XmlElement & operator=(const XmlElement &)=delete
Assignment operator. Non-copyable.
F8API int ParseAttrs(const std::string &attlst)
XmlSet * ordchildren_
Set of all child elements in file order.
POSIX regex wrapper class.
const XmlElement * GetRoot() const
std::map< std::string, std::string > XmlAttrs
F8API bool findAttrByValue(const std::string &what, const std::string &value) const
XmlSubEls * children_
simple n-ary tree
std::map< std::string, unsigned char > Str2Chr
static const Str2Chr stringtochar_
XML entity char lookup.
T & FindAttrRef(const std::string &what, T &target) const
XmlSet::const_iterator begin() const
int GetMaxDepthPermitted() const
bool GetAttrValue(std::string &target) const
const XmlElement * GetParent() const
F8API int find_child(const std::string &what, XmlSet &eset, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
const std::string * GetDecl() const
std::multimap< std::string, XmlElement * > XmlSubEls
bool FindAttrGetValue(const std::string &what, std::string &target)
F8API bool Insert(XmlElement *what)
A simple xml parser with Xpath style lookup.
XmlAttrs::const_iterator abegin() const
std::string GetPath() const
std::string GetLocString() const
virtual F8API ~XmlElement()
Dtor.
std::set< const XmlElement *, EntityOrderComp > XmlSet
static F8API const XmlSet emptyset_
F8API XmlElement(std::istream &ifs, int subidx, XmlElement *parent=nullptr, int txtline=0, int depth=0, const char *rootAttr=nullptr)
friend F8API std::ostream & operator<<(std::ostream &os, const XmlElement &en)
F8API bool GetAttr(const std::string &what, std::string &target) const
F8API const std::string & InplaceXlate(std::string &what)
bool operator()(const XmlElement *a, const XmlElement *b) const
XmlAttrs::const_iterator aend() const
const std::string & GetTag() const
static void set_flags(XmlFlags flags)
bool HasAttr(const std::string &what) const
const std::string * GetVal() const
F8API const XmlElement * find(const std::string &what, const std::string *atag=nullptr, const std::string *aval=nullptr, const char delim='/') const
static F8API const XmlAttrs emptyattrs_
XmlSet::const_iterator end() const