1

I'd like to create XML documents in a portable way in JavaScript. Coming from a Python background, I'm familiar with libraries like LXML and ElementTree, which give

  • Elements are treated as objects, by default, rather than text.
  • Documents are always tree-structured. Ie, new elements are typically appended to existing xpaths, having unclosed tags is not possible as elements always close themselves.
  • Elements children are iterable
  • Namespaces (and perhaps also namespace prefixes) are supported

Essentially, I'm looking for a neat XML creation library that works across browsers. Any recommendations?

1 Answer 1

1

If that is client-side Javascript in the browser then for creating namespace aware XML DOM documents you can use the W3C DOM Level 2 with browsers like Mozilla, Opera, Safari, Chrome and the MSXML DOM with IE (before IE 9 comes out). I do have two examples in my blog explaining the W3C DOM Level 2 namespace aware createElementNS and the MSXML createNode. Based on that you might be able to implement your own wrapper methods to hide the differences between createElementNS and createNode.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for answering but I can't help think I'm not the first person who's wanted to consume XML in multiple browsers. I'm not adverse to writing my own implementation if need be, but I'd rather not recreate the wheel if possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.