12 #ifndef ZYPP_BASE_XML_H
13 #define ZYPP_BASE_XML_H
43 struct NodeAttr :
public std::pair<std::string,std::string>
45 typedef std::pair<std::string,std::string>
Pair;
47 template <
typename _Type>
48 NodeAttr( std::string key_r,
const _Type & val_r )
52 NodeAttr( std::string key_r, std::string val_r )
53 :
Pair( std::move(key_r), std::move(val_r) )
91 Node( std::ostream & out_r, std::string name_r,
const std::initializer_list<Attr> & attrs_r = {} )
93 { printStart( attrs_r ); }
96 Node( std::ostream & out_r, std::string name_r,
Attr attr_r )
97 :
Node( out_r, std::move(name_r), { attr_r } )
103 { printStart( attrs_r ); }
113 if ( !
_name.empty() )
116 _out <<
"</" <<
_name <<
">";
123 std::ostream & operator*()
128 if ( !
_name.empty() )
135 void printStart(
const std::initializer_list<Attr> & attrs_r )
137 if ( !
_name.empty() )
139 _out <<
"<" <<
_name;
140 for (
const auto & pair : attrs_r )
141 _out <<
" " << pair.first <<
"=\"" <<
xml::escape( pair.second ) <<
"\"";
158 inline std::ostream &
node( std::ostream & out_r,
const std::string & name_r,
const std::initializer_list<Node::Attr> & attrs_r = {} )
164 inline std::ostream &
node( std::ostream & out_r,
const std::string & name_r,
Node::Attr attr_r )
165 {
return node( out_r, name_r, { attr_r } ); }
171 #endif // ZYPP_BASE_XML_H
Node(std::ostream &out_r, std::string name_r, OptionalContentType, const std::initializer_list< Attr > &attrs_r={})
Optional content ctor taking nodename and attribute list.
std::ostream & node(std::ostream &out_r, const std::string &name_r, Node::Attr attr_r)
RAII writing a nodes start/end tag.
std::string asXmlNodeAttr(const _Tp &val_r)
std::string unescape(const std::string &in_r)
Unescape xml special charaters (& -> &; from IoBind library)
(Key, Value) string pair of XML node attributes
std::pair< std::string, std::string > Pair
std::string escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).
static constexpr OptionalContentType optionalContent
NodeAttr(std::string key_r, std::string val_r)
NodeAttr(std::string key_r, const _Type &val_r)
std::ostream & node(std::ostream &out_r, const std::string &name_r, const std::initializer_list< Node::Attr > &attrs_r={})
NON_COPYABLE_BUT_MOVE(Node)
Node(std::ostream &out_r, std::string name_r, OptionalContentType, Attr attr_r)
Optional content Convenience ctor for one attribute pair.
Node(std::ostream &out_r, std::string name_r, const std::initializer_list< Attr > &attrs_r={})
Ctor taking nodename and attribute list.
std::string asString(const std::string &t)
Global asString() that works with std::string too.
Node(std::ostream &out_r, std::string name_r, Attr attr_r)
Convenience ctor for one attribute pair.