开发者

Cross platform Javascript XML tree creation, with namespaces and xpath?

开发者 https://www.devze.com 2023-02-06 22:33 出处:网络
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

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
  • Na开发者_Python百科mespaces (and perhaps also namespace prefixes) are supported

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消