window.formatXml = (xml) ->
  formatted = ''
  reg = /(>)(<)(\/*)/g
  xml = xml.replace(reg, '$1\r\n$2$3')
  pad = 0
  jQuery.each xml.split('\r\n'), (index, node) ->
    indent = 0
    if node.match(/.+<\/\w[^>]*>$/)
      indent = 0
    else if node.match(/^<\/\w/)
      if pad != 0
        pad -= 1
    else if node.match(/^<\w[^>]*[^\/]>.*$/)
      indent = 1
    else
      indent = 0
    padding = ''
    i = 0
    while i < pad
      padding += '  '
      i++
    formatted += padding + node + '\r\n'
    pad += indent
    return
  formatted
window.squashXml = (xml)->
  result = xml
    .trim()
    .replace(/^\s+/g, '')
    .replace(/\s+$/g, '')
    .replace(/>(?:\r\n|\r|\n)/g, '')
    .replace(/(?:\r\n|\r|\n)/g, ' ')
  result
