Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jonnay/jxml

Represent XML (and HTML) as JSON
https://github.com/jonnay/jxml

Last synced: about 7 hours ago
JSON representation

Represent XML (and HTML) as JSON

Awesome Lists containing this project

README

        

* jxml

Represent XML as a simple Javascript datatype. This is very similar to SXML (http://en.wikipedia.org/wiki/SXML)

Because jxml is simply an array, it is theoretically very easy to do some really cool things with it like:
- write very simple xpath like parsers
- write a simple, yet powerful, templating engine
- write xslt style transformations using json and javascript

In fact, maybe these features will make it into jxml soon. But for now it is super basic.

** Getting Started

This depends on Valentine, cause Valentine is kinda cool.
https://github.com/ded/valentine

The dependency is kinda weak though. You could easily remove it if you wanted.

Right now only one function is exported: render.

Quite simply you have an array that represents your xml, and use render to actually transform it into xml.
#+BEGIN_EXAMPLE
var j = require('jxml');
jxml.render(["html",
["head", ["title", "REPL"]],
["body",
"",
["form", {"action": "/", "method":"POST"},
"Fear the form",
["input", {"type": "text", "name":"command"}],
"With improper embedded stuff",
["input", {"type": "submit", "name":"submit"}]]]]);
#+END_EXAMPLE

This would emit:
#+BEGIN_SRC


REPL




Fear the form
With improper embedded stuff




#+END_SRC

(actually, it won't have any CRs or indenting... and you'll need to do something with the value that is returned... but you knew that.)

** Upcoming...
*** TODO there should be a jxml function, that takes xml and turns it into json
*** TODO implement a simple xpath query function
*** TODO allow the handling of functions inside of jxml for better templatey goodness and code-as-data-fun
*** TODO better PI handling
*** TODO namespaces a-la SXML?
*** TODO There might be some dom-goodness to explore here