Improve tweet selectors

This commit is contained in:
Zed
2019-06-26 19:59:28 +02:00
parent 02fcd7b880
commit 7d2fa15676
2 changed files with 12 additions and 7 deletions

View File

@@ -16,6 +16,11 @@ proc select*(node: XmlNode; selector: string): XmlNode =
let nodes = node.selectAll(selector)
if nodes.len > 0: nodes[0] else: nil
proc select*(node: XmlNode; parent, child: string): XmlNode =
let parentNode = node.select(parent)
if parentNode.isNil(): return
result = parentNode.select(child)
proc getAttr*(node: XmlNode; attr: string; default=""): string =
if node.isNil or node.attrs.isNil: return default
return node.attrs.getOrDefault(attr)