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 Tp>
48 NodeAttr( std::string key_r,
const Tp & val_r )
52 NodeAttr( std::string key_r, std::string val_r )
53 :
Pair( std::move(key_r), std::move(val_r) )
93 Node( std::ostream & out_r, std::string name_r,
const std::initializer_list<Attr> & attrs_r = {} )
95 { printStart( attrs_r ); }
98 Node( std::ostream & out_r, std::string name_r,
Attr attr_r )
99 :
Node( out_r, std::move(name_r), { attr_r } )
105 { printStart( attrs_r ); }
120 _out <<
"</" <<
_name <<
">";
127 std::ostream & operator*()
141 void printStart(
const std::initializer_list<Attr> & attrs_r )
145 _out <<
"<!--" <<
_name;
149 _out <<
"<" <<
_name;
151 for (
const auto & pair : attrs_r )
152 _out <<
" " << pair.first <<
"=\"" <<
xml::escape( pair.second ) <<
"\"";
169 inline std::ostream &
node( std::ostream & out_r,
const std::string & name_r,
const std::initializer_list<Node::Attr> & attrs_r = {} )
175 inline std::ostream &
node( std::ostream & out_r,
const std::string & name_r,
Node::Attr attr_r )
176 {
return node( out_r, name_r, { attr_r } ); }
185 inline std::ostream &
dumpAsXmlOn( std::ostream & str,
const Tp & obj,
const std::string & name_r )
188 const std::string & content(
asString( obj ) );
189 if ( ! content.empty() ) *guard <<
xml::escape( content );
196 #endif // ZYPP_BASE_XML_H
std::string asString(const Patch::Category &obj)
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 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
static constexpr OptionalContentType optionalContent
NodeAttr(std::string key_r, std::string val_r)
NodeAttr(std::string key_r, const Tp &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 asXmlNodeAttr(const Tp &val_r)
Node(std::ostream &out_r, std::string name_r, Attr attr_r)
Convenience ctor for one attribute pair.
std::ostream & dumpAsXmlOn(std::ostream &str, const Tp &obj, const std::string &name_r)
detail::EscapedString escape(const std::string &in_r)
Escape xml special charaters (& -> &; from IoBind library).