Make Node::content ignore comments and CDATA.
authorCarl Hetherington <cth@carlh.net>
Sun, 22 Apr 2018 20:52:32 +0000 (21:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 22 Apr 2018 20:52:32 +0000 (21:52 +0100)
src/cxml.cc
src/cxml.h
test/ref/a.xml

index 77770f93b0fb7ad943de5863cc72a151d79db518..3c2eda203bbf96f4aac476a8224e099885d69462 100644 (file)
@@ -220,7 +220,7 @@ cxml::Node::content () const
         xmlpp::Node::NodeList c = _node->get_children ();
        for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) {
                xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (*i);
         xmlpp::Node::NodeList c = _node->get_children ();
        for (xmlpp::Node::NodeList::const_iterator i = c.begin(); i != c.end(); ++i) {
                xmlpp::ContentNode const * v = dynamic_cast<xmlpp::ContentNode const *> (*i);
-               if (v) {
+               if (v && dynamic_cast<xmlpp::TextNode const *>(v)) {
                        content += v->get_content ();
                }
        }
                        content += v->get_content ();
                }
        }
index b7f1ef578a9093c3cb4b21e5bc3d557ca50d744e..4d01eefdd8858a6985f25451455e210214d24c83 100644 (file)
@@ -188,7 +188,7 @@ public:
                return n;
        }
 
                return n;
        }
 
-       /** @return The content of this node */
+       /** @return The text content of this node (including comments or CDATA) */
        std::string content () const;
 
        /** @return namespace URI of this node */
        std::string content () const;
 
        /** @return namespace URI of this node */
index e854aae06b40f842cf6aaf76e4e4fd28f9aba504..fa8901f8d86d36d8e26a77a462fce154eb33678a 100644 (file)
@@ -5,6 +5,6 @@
   <E>yes</E>
   <F>1</F>
   <F>2</F>
   <E>yes</E>
   <F>1</F>
   <F>2</F>
-  <H><I>testing</I><I>more testing</I></H>
+  <H><I>testing</I><I><!-- ignore this -->more testing</I></H>
   <J><K>jim</K></J>
 </A>
   <J><K>jim</K></J>
 </A>