From 2183bf77a658444c2fcd036059249981499c844c Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 15 Aug 2011 19:40:00 +0200 Subject: added xmltree.innerText; fixes #49 --- lib/pure/xmltree.nim | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/pure') diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim index 7f6d5cff8..2e56f7910 100755 --- a/lib/pure/xmltree.nim +++ b/lib/pure/xmltree.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2010 Andreas Rumpf +# (c) Copyright 2011 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -71,6 +71,15 @@ proc text*(n: PXmlNode): string {.inline.} = assert n.k in {xnText, xnComment, xnCData, xnEntity} result = n.fText +proc innerText*(n: PXmlNode): string = + ## gets the inner text of `n`. `n` has to be an ``xnElement`` node. Only + ## ``xnText`` and ``xnEntity`` nodes are considered part of `n`'s inner text, + ## other child nodes are silently ignored. + result = "" + assert n.k == xnElement + for i in 0 .. n.s.len-1: + if n.s[i].k in {xnText, xnEntity}: result.add(n.fText) + proc tag*(n: PXmlNode): string {.inline.} = ## gets the tag name of `n`. `n` has to be an ``xnElement`` node. assert n.k == xnElement -- cgit 1.4.1-2-gfad0