summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-08-15 19:40:00 +0200
committerAraq <rumpf_a@web.de>2011-08-15 19:40:00 +0200
commit2183bf77a658444c2fcd036059249981499c844c (patch)
treedd1ed092f24f0448f75883c21d145166435d0728 /lib
parentc6038dda04b9c28d20bb9a1baaa226f2ecdd1f5c (diff)
downloadNim-2183bf77a658444c2fcd036059249981499c844c.tar.gz
added xmltree.innerText; fixes #49
Diffstat (limited to 'lib')
-rwxr-xr-xlib/pure/xmltree.nim11
1 files changed, 10 insertions, 1 deletions
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