get list of child nodes
This commit is contained in:
@@ -47,10 +47,6 @@
|
||||
there of).
|
||||
|
||||
<code>
|
||||
#include <xml-cxx/xml.hxx>
|
||||
#include <iostream>
|
||||
#include <<stream>
|
||||
[...]
|
||||
xml::Factory test(xml::Node("persons") // root node
|
||||
<<(xml::Node("person") // child of persons
|
||||
.attr("id", xml::mandatory)
|
||||
@@ -59,13 +55,11 @@
|
||||
<<(xml::Node("friends") // friends of person
|
||||
<<(xml::Node("friend") // a friend
|
||||
.attr("id", xml::mandatory)))));
|
||||
[...]
|
||||
try {
|
||||
std::auto_ptr<xml::Node> persons(test.read(std::ifstream("file.xml)));
|
||||
// Here we can be sure, that our structure is valid,
|
||||
// but we must check optional elements before access, otherwise
|
||||
// we get an exception.
|
||||
[...]
|
||||
for (xml::Node::size_type i(0); i<persons.children(); ++i) {
|
||||
std::cout<<"Person: "<<*persons[i]["name"]; // exception if no "name"
|
||||
if (persons[i]("friends")) // check if "friends" is set
|
||||
@@ -74,7 +68,6 @@
|
||||
std::cout<<" has no friend list";
|
||||
std::cout<<std::endl;
|
||||
}
|
||||
[...]
|
||||
} catch (const std::exception& x) {
|
||||
std::cerr<<"**** Error in file \"file.xml\":"<<std::endl
|
||||
<<x.what()<<std::endl;
|
||||
@@ -301,6 +294,7 @@ namespace xml {
|
||||
typedef std::vector<Node*> Contents;
|
||||
public:
|
||||
typedef Contents::size_type size_type;
|
||||
typedef std::vector<Node*> List;
|
||||
Node(std::string name) throw();
|
||||
Node(const Node& o) throw();
|
||||
Node& operator=(const Node& o) throw();
|
||||
@@ -321,6 +315,7 @@ namespace xml {
|
||||
Node& attr(const std::string& name, bool mandatory) throw();
|
||||
std::string attr(const std::string& name) const throw();
|
||||
std::string& attr(const std::string& name) throw();
|
||||
List list(const std::string& name) const throw();
|
||||
bool operator()(const std::string& child) const throw();
|
||||
Node& operator<<(const Node& o) throw(cannot_have_children);
|
||||
Node& operator<<(const Attributes& o) throw();
|
||||
|
Reference in New Issue
Block a user