From 328adf304b8b3cb61f7e7d808ea9574928a08845 Mon Sep 17 00:00:00 2001 From: randomdan Date: Wed, 23 Jan 2013 21:17:00 +0000 Subject: Don't add null values to the XML output tree Include part info where available in guide --- project2/xml/xmlPresenter.cpp | 20 ++++++++++++++++++++ project2/xml/xmlPresenter.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index 9982a43..075518c 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -153,6 +153,26 @@ XmlPresenter::addAttribute(const Glib::ustring & name, const Glib::ustring & ns, } } +void +XmlPresenter::addNamedValue(const Glib::ustring & name, const VariableType & value) const +{ + if (!value.isNull()) { + pushSub(name, Glib::ustring()); + addText(value); + popSub(); + } +} + +void +XmlPresenter::addNamedValue(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const +{ + if (!value.isNull()) { + pushSub(name, ns); + addText(value); + popSub(); + } +} + class XmlNodeWriter : public boost::static_visitor { public: XmlNodeWriter(xmlpp::Element * n) : node(n) { } diff --git a/project2/xml/xmlPresenter.h b/project2/xml/xmlPresenter.h index 744ef3d..79d9634 100644 --- a/project2/xml/xmlPresenter.h +++ b/project2/xml/xmlPresenter.h @@ -30,6 +30,8 @@ class XmlPresenter : public Presenter, public ContentPresenter, public SourceOf< void pushSub(const Glib::ustring & name, const Glib::ustring & ns) const; void addAttribute(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const; void addText(const VariableType & value) const; + void addNamedValue(const Glib::ustring & name, const VariableType & value) const; + void addNamedValue(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const; void popSub() const; void addNewArray(const Glib::ustring&, bool objects) const; void finishArray(bool objects) const; -- cgit v1.2.3