get list of child nodes
This commit is contained in:
20
install-64-and-32-bit-linux.sh
Executable file
20
install-64-and-32-bit-linux.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
./bootstrap.sh && \
|
||||||
|
./configure && \
|
||||||
|
make && \
|
||||||
|
sudo make install && \
|
||||||
|
make clean && \
|
||||||
|
LDFLAGS="-L/usr/lib32 -m32" CXXFLAGS="-m32" ./configure \
|
||||||
|
--libdir=/usr/local/lib32 \
|
||||||
|
--build=x86_64 \
|
||||||
|
--host=i386 && \
|
||||||
|
make && \
|
||||||
|
sudo make install && \
|
||||||
|
make clean && \
|
||||||
|
./configure \
|
||||||
|
--prefix=/opt/local/i586-mingw32msvc \
|
||||||
|
--build=x86_64 \
|
||||||
|
--host=i586-mingw32msvc && \
|
||||||
|
make && \
|
||||||
|
sudo make install && \
|
||||||
|
make clean
|
||||||
|
|
@@ -47,10 +47,6 @@
|
|||||||
there of).
|
there of).
|
||||||
|
|
||||||
<code>
|
<code>
|
||||||
#include <xml-cxx/xml.hxx>
|
|
||||||
#include <iostream>
|
|
||||||
#include <<stream>
|
|
||||||
[...]
|
|
||||||
xml::Factory test(xml::Node("persons") // root node
|
xml::Factory test(xml::Node("persons") // root node
|
||||||
<<(xml::Node("person") // child of persons
|
<<(xml::Node("person") // child of persons
|
||||||
.attr("id", xml::mandatory)
|
.attr("id", xml::mandatory)
|
||||||
@@ -59,13 +55,11 @@
|
|||||||
<<(xml::Node("friends") // friends of person
|
<<(xml::Node("friends") // friends of person
|
||||||
<<(xml::Node("friend") // a friend
|
<<(xml::Node("friend") // a friend
|
||||||
.attr("id", xml::mandatory)))));
|
.attr("id", xml::mandatory)))));
|
||||||
[...]
|
|
||||||
try {
|
try {
|
||||||
std::auto_ptr<xml::Node> persons(test.read(std::ifstream("file.xml)));
|
std::auto_ptr<xml::Node> persons(test.read(std::ifstream("file.xml)));
|
||||||
// Here we can be sure, that our structure is valid,
|
// Here we can be sure, that our structure is valid,
|
||||||
// but we must check optional elements before access, otherwise
|
// but we must check optional elements before access, otherwise
|
||||||
// we get an exception.
|
// we get an exception.
|
||||||
[...]
|
|
||||||
for (xml::Node::size_type i(0); i<persons.children(); ++i) {
|
for (xml::Node::size_type i(0); i<persons.children(); ++i) {
|
||||||
std::cout<<"Person: "<<*persons[i]["name"]; // exception if no "name"
|
std::cout<<"Person: "<<*persons[i]["name"]; // exception if no "name"
|
||||||
if (persons[i]("friends")) // check if "friends" is set
|
if (persons[i]("friends")) // check if "friends" is set
|
||||||
@@ -74,7 +68,6 @@
|
|||||||
std::cout<<" has no friend list";
|
std::cout<<" has no friend list";
|
||||||
std::cout<<std::endl;
|
std::cout<<std::endl;
|
||||||
}
|
}
|
||||||
[...]
|
|
||||||
} catch (const std::exception& x) {
|
} catch (const std::exception& x) {
|
||||||
std::cerr<<"**** Error in file \"file.xml\":"<<std::endl
|
std::cerr<<"**** Error in file \"file.xml\":"<<std::endl
|
||||||
<<x.what()<<std::endl;
|
<<x.what()<<std::endl;
|
||||||
@@ -301,6 +294,7 @@ namespace xml {
|
|||||||
typedef std::vector<Node*> Contents;
|
typedef std::vector<Node*> Contents;
|
||||||
public:
|
public:
|
||||||
typedef Contents::size_type size_type;
|
typedef Contents::size_type size_type;
|
||||||
|
typedef std::vector<Node*> List;
|
||||||
Node(std::string name) throw();
|
Node(std::string name) throw();
|
||||||
Node(const Node& o) throw();
|
Node(const Node& o) throw();
|
||||||
Node& operator=(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();
|
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) const throw();
|
||||||
std::string& attr(const std::string& name) 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();
|
bool operator()(const std::string& child) const throw();
|
||||||
Node& operator<<(const Node& o) throw(cannot_have_children);
|
Node& operator<<(const Node& o) throw(cannot_have_children);
|
||||||
Node& operator<<(const Attributes& o) throw();
|
Node& operator<<(const Attributes& o) throw();
|
||||||
|
@@ -283,9 +283,16 @@ namespace xml {
|
|||||||
if (it!=_attributes.end()) return it->second;
|
if (it!=_attributes.end()) return it->second;
|
||||||
return std::string();
|
return std::string();
|
||||||
}
|
}
|
||||||
std::string& Node::attr(const std::string&name) throw() {
|
std::string& Node::attr(const std::string& name) throw() {
|
||||||
return _attributes[name];
|
return _attributes[name];
|
||||||
}
|
}
|
||||||
|
Node::List Node::list(const std::string& name) const throw() {
|
||||||
|
List res;
|
||||||
|
for (Contents::const_iterator it(_contents.begin());
|
||||||
|
it!=_contents.end(); ++it)
|
||||||
|
if ((*it)->_name==name) res.push_back(*it);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
bool Node::operator()(const std::string& child) const throw() {
|
bool Node::operator()(const std::string& child) const throw() {
|
||||||
return find(child);
|
return find(child);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user