1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/xml/Parse.h
12 #ifndef ZYPP_PARSER_XML_PARSE_H
13 #define ZYPP_PARSER_XML_PARSE_H
17 #include "zypp/parser/xml/Reader.h"
18 #include "zypp/parser/xml/ParseDef.h"
19 #include "zypp/parser/xml/ParseDefConsume.h"
21 ///////////////////////////////////////////////////////////////////
23 { /////////////////////////////////////////////////////////////////
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
28 /** Parse xml \c input_r and store data in \c data_r.
30 * \c TData must be defaultconstructible and assignable.
32 * \c TData::RootNode must be a \ref xml::ParseDef constructible
35 * \throws ParseDefException on parse errors.
37 * To parse a xml file like this:
40 * <setup attr="13">value</setup>
46 * You need something like this:
53 * std:list<std::string> names;
56 * // Convenience parsing to *this.
57 * void parse( const Pathname & path_r )
58 * { xml::rnParse( path_r, *this ); }
61 * // Parser description
62 * struct RootNode : public xml::ParseDef
64 * RootNode( XmlData & data )
65 * : ParseDef( "test", MANDTAORY )
69 * ("setup", MANDTAORY,
70 * xml::parseDefAssign( data.value )
71 * ( "attr", data.attr ) )
72 * // Each individual list entry is collected locally
73 * // and appended to the list after the node is done.
74 * ("list", MULTIPLE_OPTIONAL,
75 * xml::parseDefAssign( "name", _cname )
76 * >> bind( &RootNode::cdone, this, _1 ) )
80 * void cdone( const xml::Node & node_r )
82 * _data.push_back( _cname );
83 * _cname.clear(); // prepare for next
87 * XmlData & _data; // stored just because notification callbacks are used.
93 * xmlData.parse( "/tmp/mytest.xml" );
97 inline void rnParse( const InputStream & input_r, TData & data_r )
99 typedef typename TData::RootNode RootNode;
102 xml::Reader reader( input_r );
103 RootNode rootNode( pdata );
104 rootNode.take( reader );
109 /////////////////////////////////////////////////////////////////
111 ///////////////////////////////////////////////////////////////////
112 /////////////////////////////////////////////////////////////////
114 ///////////////////////////////////////////////////////////////////
115 #endif // ZYPP_PARSER_XML_PARSEDEF_H