diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-04-22 21:52:32 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-04-22 21:52:32 +0100 |
| commit | a45e4307d377da9fbd17890a3701b443eef5b94e (patch) | |
| tree | 19812b86522bb5d510dc6ecb6247f95bba5c480e | |
| parent | abec1be888ad42013e3e45d22984420fd26892f3 (diff) | |
Make Node::content ignore comments and CDATA.
| -rw-r--r-- | src/cxml.cc | 2 | ||||
| -rw-r--r-- | src/cxml.h | 2 | ||||
| -rw-r--r-- | test/ref/a.xml | 2 |
3 files changed, 3 insertions, 3 deletions
diff --git a/src/cxml.cc b/src/cxml.cc index 77770f9..3c2eda2 100644 --- a/src/cxml.cc +++ b/src/cxml.cc @@ -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); - if (v) { + if (v && dynamic_cast<xmlpp::TextNode const *>(v)) { content += v->get_content (); } } @@ -188,7 +188,7 @@ public: 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 */ diff --git a/test/ref/a.xml b/test/ref/a.xml index e854aae..fa8901f 100644 --- a/test/ref/a.xml +++ b/test/ref/a.xml @@ -5,6 +5,6 @@ <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> |
