Parsing and printing XML

Representation of XML trees

For example,

<p:a xmlns:p="<http://example.com/p>">
  Text 1
  <p:b att1="one" att2="two">
    <q:a xmlns:q="<http://example.com/q>" p:att3="three">
    Text 2
    </q:a>
  </p:b>
  Text 3
</p:a>

is represented as (ignoring whitespace):

xml.elementNode({
  name: "p:a",
  space: "<http://example.com/p>",
  prefix: "p",
  local: "a",
  props: {},
  children: [
    xml.textNode("Text 1"),
    xml.elementNode({
      name: "p:b",
      space: "<http://example.com/p>",
      prefix: "p",
      local: "b",
      props: {
        "att1": { name:"att1", space:"", prefix:"", local:"att1", value:"one" },
        "att2": { name:"att1", space:"", prefix:"", local:"att2", value:"two" }
      },
      children: [
        xml.elementNode({
          name: "q:a",
          space: "<http://example.com/p>",
          prefix: "q",
          local: "a",
          props: {
            "p:att3": { name:"p:att3", space:"<http://example.com/p>", prefix:"p", local:"att3", value:"three" }
          }.
          children: [ xml.textNode("Text 2") ]
        })
      ]
    }),
    xml.textNode("Text 3")
  ]
})

Notes: