From 3cf945fbcc36d73545837ce9e00f923b6df80d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 11 Feb 2014 17:20:11 +0100 Subject: [PATCH] Feature #2694: Improve ObjectCollection::from_xml_node It could not parse xml with space between elements (cherry picked from commit c026120a17659129e269ba25ce01ecdaea17ee01) --- src/pool/ObjectCollection.cc | 46 ++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/src/pool/ObjectCollection.cc b/src/pool/ObjectCollection.cc index 91e5ceaf2d..0157df4155 100644 --- a/src/pool/ObjectCollection.cc +++ b/src/pool/ObjectCollection.cc @@ -21,37 +21,33 @@ int ObjectCollection::from_xml_node(const xmlNodePtr node) { - xmlNodePtr cur_node = 0; istringstream iss; int id; int rc = 0; + ostringstream oss; - for (cur_node = node->children; cur_node != 0; cur_node = cur_node->next) + vector::iterator it; + + ObjectXML oxml(node); + + oss << "/" << collection_name << "/ID"; + vector ids = oxml[oss.str().c_str()]; + + for (it = ids.begin(); it != ids.end(); it++) { - if ((cur_node->type == XML_ELEMENT_NODE) && - (cur_node->children != 0) && - ((cur_node->children->type == XML_TEXT_NODE ) || - (cur_node->children->type == XML_CDATA_SECTION_NODE))) - { - iss.clear(); - iss.str(reinterpret_cast(cur_node->children->content)); - iss >> dec >> id; + iss.clear(); + iss.str(*it); + iss >> dec >> id; - if ( iss.fail() ) - { - rc = -1; - break; - } - else - { - collection_set.insert(id); - } - } - else - { - rc = -1; - break; - } + if ( iss.fail() ) + { + rc = -1; + break; + } + else + { + collection_set.insert(id); + } } return rc;