[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5418] Add a convenience function for writing comments in
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5418] Add a convenience function for writing comments in xml documents |
Date: |
Wed, 07 Mar 2012 10:25:12 +0000 |
Revision: 5418
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5418
Author: chicares
Date: 2012-03-07 10:25:11 +0000 (Wed, 07 Mar 2012)
Log Message:
-----------
Add a convenience function for writing comments in xml documents
Modified Paths:
--------------
lmi/trunk/xml_lmi.cpp
lmi/trunk/xml_lmi.hpp
Modified: lmi/trunk/xml_lmi.cpp
===================================================================
--- lmi/trunk/xml_lmi.cpp 2012-03-06 17:42:18 UTC (rev 5417)
+++ lmi/trunk/xml_lmi.cpp 2012-03-07 10:25:11 UTC (rev 5418)
@@ -263,6 +263,25 @@
return s;
}
+/// Add an xml comment just before the root (first element node).
+///
+/// For readability, the comment is padded with single spaces.
+
+void xml_lmi::xml_document::add_comment(std::string const& s)
+{
+ xml::node::iterator i = document_->begin();
+ for(xml::node::iterator i = document_->begin(); i != document_->end(); ++i)
+ {
+ if(xml::node::type_element == i->get_type())
+ {
+ std::string t = ' ' + s + ' ';
+ document_->insert(i, xml::node(xml::node::comment(t.c_str())));
+ return;
+ }
+ }
+ fatal_error() << "Cannot add comment to rootless document." << LMI_FLUSH;
+}
+
xml::node::const_iterator retrieve_element
(xml::element const& parent
,std::string const& name
Modified: lmi/trunk/xml_lmi.hpp
===================================================================
--- lmi/trunk/xml_lmi.hpp 2012-03-06 17:42:18 UTC (rev 5417)
+++ lmi/trunk/xml_lmi.hpp 2012-03-07 10:25:11 UTC (rev 5418)
@@ -73,6 +73,8 @@
void save(std::string const& filename);
std::string str();
+ void add_comment(std::string const&);
+
private:
std::string error_context_;
boost::scoped_ptr<Document> document_;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5418] Add a convenience function for writing comments in xml documents,
Greg Chicares <=