[Xmlstorage-commits] SF.net SVN: xmlstorage: [79] trunk/c++
Brought to you by:
martinfuchs
From: <mar...@us...> - 2008-01-31 23:22:36
|
Revision: 79 http://xmlstorage.svn.sourceforge.net/xmlstorage/?rev=79&view=rev Author: martinfuchs Date: 2008-01-31 15:22:34 -0800 (Thu, 31 Jan 2008) Log Message: ----------- add remove_children() and erase() to remove named children and attributes Modified Paths: -------------- trunk/c++/example5.cpp trunk/c++/xmlstorage.h Modified: trunk/c++/example5.cpp =================================================================== --- trunk/c++/example5.cpp 2008-01-31 23:21:12 UTC (rev 78) +++ trunk/c++/example5.cpp 2008-01-31 23:22:34 UTC (rev 79) @@ -45,55 +45,60 @@ void test_write() { - XMLDoc doc; - XMLPos pos(&doc); + XMLDoc doc; + XMLPos pos(&doc); - // Zusammenstellen der XML-Struktur im Dokument 'doc' - pos.create("PERSON"); + // Zusammenstellen der XML-Struktur im Dokument 'doc' + pos.create("PERSON"); - pos.create("NAME"); - pos->set_content("Mustername"); - pos.back(); // </NAME> + pos.create("NAME"); + pos->set_content("Mustername"); + pos.back(); // </NAME> - pos.create("VORNAME"); - pos->set_content("Mustervorname"); - pos.back(); // </VORNAME> + pos.create("VORNAME"); + pos->set_content("Mustervorname"); + pos.back(); // </VORNAME> - pos.create("ADRESSE"); - pos->set_content("Musteradresse"); - pos.back(); // </ADRESSE> + pos.create("ADRESSE"); + pos["private"] = "true"; + pos->set_content("Musteradresse"); + pos.back(); // </ADRESSE> pos.back(); // </PERSON> - // Schreiben der XML-Datei - doc.write_file("example5.xml"); + // Schreiben der XML-Datei + doc.write_file("example5.xml"); } void test_delete() { - XMLDoc doc; + XMLDoc doc; - // Einlesen des XML-Files - doc.read_file("example5.xml"); + // Einlesen des XML-Files + doc.read_file("example5.xml"); - XMLPos pos(&doc); + XMLPos pos(&doc); - pos.go_down("PERSON"); +// pos.remove_children("VORNAME"); pos.go_down("VORNAME"); pos.delete_this(); pos.back(); // </PERSON> - // Schreiben der XML-Datei - doc.write_file("example5.xml"); + pos.go_down("ADRESSE"); + pos.erase("private"); + pos.back(); + + // Schreiben der XML-Datei + doc.write_file("example5.xml"); } int main() { - test_write(); - test_delete(); + test_write(); + test_delete(); - return 0; + return 0; } Modified: trunk/c++/xmlstorage.h =================================================================== --- trunk/c++/xmlstorage.h 2008-01-31 23:21:12 UTC (rev 78) +++ trunk/c++/xmlstorage.h 2008-01-31 23:22:34 UTC (rev 79) @@ -942,6 +942,16 @@ _children.push_back(child); } + /// remove all children named 'name' + void remove_children(const XS_String& name) + { + Children::iterator it, next=_children.begin(); + + while((it=next++)!=_children.end()) + if (**it == name) + _children.erase(it); + } + /// write access to an attribute void put(const XS_String& attr_name, const XS_String& value) { @@ -965,6 +975,12 @@ return def; } + /// remove the attribute 'attr_name' + void erase(const XS_String& attr_name) + { + _attributes.erase(attr_name); + } + /// convenient value access in children node XS_String subvalue(const XS_String& name, const XS_String& attr_name, int n=0) const { @@ -1460,21 +1476,6 @@ return false; } - /// delete current node and go back to previous position - bool delete_this() - { - if (!_stack.empty()) { - XMLNode* pLast = _stack.top(); - - if (pLast->_children.remove(_cur)) { - _cur = _stack.top(); - return true; - } - } - - return false; - } - /// go down to first child bool go_down() { @@ -1590,6 +1591,33 @@ } #endif + /// delete current node and go back to previous position + bool delete_this() + { + if (!_stack.empty()) { + XMLNode* pLast = _stack.top(); + + if (pLast->_children.remove(_cur)) { + _cur = _stack.top(); + return true; + } + } + + return false; + } + + /// remove all children named 'name' + void remove_children(const XS_String& name) + { + _cur->remove_children(name); + } + + /// remove the attribute 'attr_name' from the current node + void erase(const XS_String& attr_name) + { + _cur->erase(attr_name); + } + XS_String& str() {return *_cur;} const XS_String& str() const {return *_cur;} @@ -2046,6 +2074,7 @@ }; + // read option (for example configuration) values from XML node attributes template<typename T> inline void read_option(T& var, const_XMLPos& cfg, LPCXSSTR key) { @@ -2055,6 +2084,7 @@ var = val; } + // read integer option values from XML node attributes template<> inline void read_option(int& var, const_XMLPos& cfg, LPCXSSTR key) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |