summaryrefslogtreecommitdiff
path: root/project2/xmlObjectLoader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlObjectLoader.cpp')
-rw-r--r--project2/xmlObjectLoader.cpp46
1 files changed, 34 insertions, 12 deletions
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index 9b4b24b..e789275 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -12,16 +12,26 @@ LoaderBase::getMap()
return loaders;
}
+LoaderBase::LoaderBase(const Glib::ustring & n, bool r) :
+ recursive(r),
+ ns(n)
+{
+}
+
+LoaderBase::~LoaderBase()
+{
+}
+
void
-LoaderBase::collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) const
+LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly) const
{
if (!node) {
return;
}
depth += 1;
- if (!childrenOnly && ns == node->get_namespace_prefix()) {
+ unsigned int created = 0;
+ if (!childrenOnly && node->get_namespace_uri() == ns) {
Glib::ustring name = node->get_name();
- unsigned int created = 0;
unsigned int stored = 0;
for(ElementLoaderMap::const_iterator i = getMap().lower_bound(name); i != getMap().upper_bound(name); i++) {
Project2SourceObject o = i->second->go(node);
@@ -33,17 +43,13 @@ LoaderBase::collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bo
}
}
}
- if (created < 1) {
- fprintf(stderr, "Didn't create any objects for %s:%s\n", ns.c_str(), name.c_str());
- throw std::runtime_error("Unknown object");
- }
- if (stored < 1) {
- throw std::runtime_error("Unsupported object");
+ if (stored < created) {
+ throw std::runtime_error("Unexpected object");
}
}
- else if (recursive || childrenOnly) {
- BOOST_FOREACH(xmlpp::Node * child, node->get_children()) {
- collectAll(ns, dynamic_cast<const xmlpp::Element *>(child), recursive, false);
+ if (created == 0 && (recursive || childrenOnly)) {
+ BOOST_FOREACH(const xmlpp::Node * child, node->get_children()) {
+ collectAll(dynamic_cast<const xmlpp::Element *>(child), false);
}
}
depth -= 1;
@@ -84,6 +90,22 @@ ElementLoader::onIdle()
{
}
+Glib::ustring
+xmlChildText(const xmlpp::Node * p, const Glib::ustring & t)
+{
+ Glib::ustring rtn;
+ BOOST_FOREACH(const xmlpp::Node * child, p->get_children(t)) {
+ const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(child);
+ if (e) {
+ const xmlpp::ContentNode * cn = e->get_child_text();
+ if (cn) {
+ rtn += cn->get_content();
+ }
+ }
+ }
+ return rtn;
+}
+
void
ElementLoader::onIteration()
{