     n.parent = @
 
   appendTo: (prev) ->
-    if @level > prev.level
-      if @type is 'attribute'
-        prev.setAttribute @name, @value
-        return prev
-      else if @type is 'element' or @type is 'empty element'
-        prev.appendChild @
-        return @
-      else if @type is 'text'
-        prev.appendChild @
-        return @
-      else
-        throw new Error 'unknown type'
-    else if @level is prev.level
-      if @type is 'attribute'
-        throw new Error()
-      else if @type is 'element' or @type is 'empty element'
-        prev.parent.appendChild @
-        return @
-      else if @type is 'text'
-        prev.parent.appendChild @
-        return @
-      else
-        throw new Error 'unknown type'
-    else if @level < prev.level
-      if @type is 'attribute'
-        throw new Error()
-      else if @type is 'element' or @type is 'empty element'
-        p = prev
-        p = p.parent until p.level is @level
-        p.parent.appendChild @
-        return @
-      else if @type is 'text'
-        p = prev
-        p = p.parent until p.level is @level
-        p.parent.appendChild @
-        return @
-      else
-        throw new Error 'unknown type'
-    @
+    @parsed.append.apply @, [prev]
 
   write: ->
     @parsed.write.apply @, []

        name: s
        type: 'text'
        value: null
        write: -> s
    ].some (f) ->
      parsed = f node

    name: m[1]
    type: 'attribute'
    value: m[2]
    append: (prev) ->
      if @level > prev.level
        prev.setAttribute @name, @value
        prev
      else
        throw new Error()
    write: ->
      throw new Error()

