summary refs log tree commit diff stats
path: root/lib/pure/xmltree.nim
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
committerAraq <rumpf_a@web.de>2011-04-01 15:07:16 +0200
commit4741e8f9a1d1148d58e129626952219e14ede255 (patch)
treedb2eca2249ccc3230dc6c0a7359986198cab4048 /lib/pure/xmltree.nim
parentdc669155e39007f1b584eef247dff90523f836bf (diff)
downloadNim-4741e8f9a1d1148d58e129626952219e14ede255.tar.gz
ugh, maybe broke git
Diffstat (limited to 'lib/pure/xmltree.nim')
-rwxr-xr-xlib/pure/xmltree.nim19
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/pure/xmltree.nim b/lib/pure/xmltree.nim
index 57988698b..41765b87a 100755
--- a/lib/pure/xmltree.nim
+++ b/lib/pure/xmltree.nim
@@ -98,17 +98,17 @@ iterator items*(n: PXmlNode): PXmlNode {.inline.} =
   assert n.k == xnElement
   for i in 0 .. n.len-1: yield n[i]
 
-proc attr*(n: PXmlNode): PXmlAttributes {.inline.} = 
+proc attrs*(n: PXmlNode): PXmlAttributes {.inline.} = 
   ## gets the attributes belonging to `n`.
   assert n.k == xnElement
   result = n.fAttr
   
-proc `attr=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} = 
+proc `attrs=`*(n: PXmlNode, attr: PXmlAttributes) {.inline.} = 
   ## sets the attributes belonging to `n`.
   assert n.k == xnElement
   n.fAttr = attr
 
-proc attrLen*(n: PXmlNode): int {.inline.} = 
+proc attrsLen*(n: PXmlNode): int {.inline.} = 
   ## returns the number of `n`'s attributes.
   assert n.k == xnElement
   if not isNil(n.fAttr): result = len(n.fAttr)
@@ -262,3 +262,16 @@ macro `<>`*(x: expr): expr =
   ##
   result = xmlConstructor(x)
 
+proc child*(n: PXmlNode, name: string): PXmlNode =
+  ## Finds the first child element of `n` with a name of `name`.
+  ## Returns `nil` on failure.
+  assert n.kind == xnElement
+  for i in items(n):
+    if i.kind == xnElement:
+      if i.tag == name:
+        return i
+
+proc attr*(n: PXmlNode, name: string): string =
+  ## Finds the first attribute of `n` with a name of `name`.
+  assert n.kind == xnElement
+  return n.attrs[name]