summaryrefslogtreecommitdiff
path: root/src/cxml.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-10-10 21:38:50 +0100
committerCarl Hetherington <cth@carlh.net>2014-10-10 21:38:50 +0100
commit5800b1958cfb055fe1fb30461cbf73fb50e59e12 (patch)
tree338ed834582006126600866bfd0a775107b1f7e6 /src/cxml.cc
parented60523d354af3b18150da1e183e80dc52ee851a (diff)
Sort out xmlns stuff.
Diffstat (limited to 'src/cxml.cc')
-rw-r--r--src/cxml.cc33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/cxml.cc b/src/cxml.cc
index 3285fe6..8bfb923 100644
--- a/src/cxml.cc
+++ b/src/cxml.cc
@@ -79,7 +79,11 @@ cxml::Node::write (xmlpp::Node* parent) const
node->add_child_text (_content);
}
- for (list<pair<string, string> >::const_iterator i = _attributes.begin(); i != _attributes.end(); ++i) {
+ for (KeyValueList::const_iterator i = _namespace_declarations.begin(); i != _namespace_declarations.end(); ++i) {
+ node->set_namespace_declaration (i->first, i->second);
+ }
+
+ for (KeyValueList::const_iterator i = _attributes.begin(); i != _attributes.end(); ++i) {
node->set_attribute (i->first, i->second);
}
@@ -183,7 +187,7 @@ cxml::Node::ignore_child (string name) const
string
cxml::Node::string_attribute (string name) const
{
- list<pair<string, string> >::const_iterator i = _attributes.begin ();
+ KeyValueList::const_iterator i = _attributes.begin ();
while (i != _attributes.end() && i->first != name) {
++i;
}
@@ -198,7 +202,7 @@ cxml::Node::string_attribute (string name) const
optional<string>
cxml::Node::optional_string_attribute (string name) const
{
- list<pair<string, string> >::const_iterator i;
+ KeyValueList::const_iterator i;
while (i != _attributes.end() && i->first != name) {
++i;
}
@@ -253,7 +257,7 @@ cxml::Node::namespace_prefix () const
void
cxml::Node::set_attribute (string name, string value)
{
- list<pair<string, string> >::iterator i = _attributes.begin ();
+ KeyValueList::iterator i = _attributes.begin ();
while (i != _attributes.end() && i->first != name) {
++i;
}
@@ -265,6 +269,21 @@ cxml::Node::set_attribute (string name, string value)
_attributes.push_back (make_pair (name, value));
}
+void
+cxml::Node::set_namespace_declaration (string uri, string ns)
+{
+ KeyValueList::iterator i = _namespace_declarations.begin ();
+ while (i != _namespace_declarations.end() && i->second != ns) {
+ ++i;
+ }
+
+ if (i != _namespace_declarations.end ()) {
+ _namespace_declarations.erase (i);
+ }
+
+ _namespace_declarations.push_back (make_pair (uri, ns));
+}
+
cxml::NodePtr
cxml::read_file (boost::filesystem::path file)
{
@@ -304,6 +323,12 @@ static void
write_to_xmlpp_document (cxml::ConstNodePtr node, xmlpp::Document& doc)
{
xmlpp::Element* root = doc.create_root_node (node->name ());
+
+ cxml::KeyValueList namespace_declarations = node->namespace_declarations ();
+ for (cxml::KeyValueList::const_iterator i = namespace_declarations.begin(); i != namespace_declarations.end(); ++i) {
+ root->set_namespace_declaration (i->first, i->second);
+ }
+
cxml::NodeList children = node->children ();
for (cxml::NodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
(*i)->write (root);