daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest Oct 19th, 2018 130 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. elementTree = (node) ->
  2.     element = []
  3.     element.tag = node.tagName
  4.     element.attrib = {}
  5.     for attribute in node.attributes
  6.         element.attrib[attribute.name] = attribute.value
  7.     element.text = ''
  8.     element.tail = ''
  9.  
  10.     last_element = null
  11.     for child, i in node.childNodes
  12.         if child.tagName
  13.             last_element = element.push elementTree(child)
  14.         else
  15.             value = child.textContent.replace(/\s/g, ' ')
  16.             if value != ' '
  17.                 if last_element
  18.                     last_element.tail += value
  19.                 else
  20.                     element.text += value
  21.  
  22.     element.findall = (pattern) ->
  23.         parts = pattern.split('/')
  24.         result = [@]
  25.         while parts.length > 0
  26.             tag = parts.shift()
  27.             matches = result
  28.             result = []
  29.             for node in matches
  30.                 for child in node
  31.                     if tag == '*'
  32.                         result.push(child)
  33.                     else if child.tag == tag
  34.                         result.push(child)
  35.         return result
  36.  
  37.     element.find = (pattern) ->
  38.         return @findall(pattern)[0]
  39.  
  40.     element.findtext = (pattern) ->
  41.         return @find(pattern).text
  42.  
  43.     return element
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top