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

https://github.com/funcool/tubax

Clojurescript XML parser
https://github.com/funcool/tubax

Last synced: 6 months ago
JSON representation

Clojurescript XML parser

Awesome Lists containing this project

README

          

tubax
========
http://en.wikipedia.org/wiki/Tubax


While the timbre of the E♭ tubax is more focused and compact than that of the full-sized contrabass saxophone.

## Rationale
Currently there is no good way to parse XML and other markup languages with Clojurescript. There are no Clojurescript-based libraries and most of the Javascript ones require access to the DOM.

This last point is critical because HTML5 Web Workers don't have access to these APIs so an alternative is necessary.

Also we're aiming to be fully compatible with the clojure.xml format so we can use helping functions inside the Clojure library.

## Usage

[![Clojars Project](http://clojars.org/funcool/tubax/latest-version.svg)](http://clojars.org/funcool/tubax)

*Tubax* uses behind the scenes [sax-js](https://github.com/isaacs/sax-js) a very lightweight library for for XML parsing based on SAX (simple api for xml).

You can check full documentation here: http://funcool.github.io/tubax

A basic usage example:

```clojure
(def xml "

RSS Title
This is an example of an RSS feed
http://www.example.com/main.html
Mon, 06 Sep 2010 00:01:00 +0000
Sun, 06 Sep 2009 16:20:00 +0000
1800

Example entry
Here is some text containing an interesting description.
http://www.example.com/blog/post/1
7bd204c6-1655-4c27-aeee-53f933c5395f
Sun, 06 Sep 2009 16:20:00 +0000


Example entry2
Here is some text containing an interesting description.
http://www.example.com/blog/post/1
7bd204c6-1655-4c27-aeee-53f933c5395f
Sun, 06 Sep 2009 16:20:00 +0000


")

(core/xml->clj xml)

;; => {:tag :rss :attributes {:version "2.0"}
;; :content
;; [{:tag :channel :attributes {}
;; :content
;; [{:tag :title :attributes {} :content ["RSS Title"]}
;; {:tag :description :attributes {} :content ["This is an example of an RSS feed"]}
;; {:tag :link :attributes {} :content ["http://www.example.com/main.html"]}
;; {:tag :lastBuildDate :attributes {} :content ["Mon, 06 Sep 2010 00:01:00 +0000"]}
;; {:tag :pubDate :attributes {} :content ["Sun, 06 Sep 2009 16:20:00 +0000"]}
;; {:tag :ttl :attributes {} :content ["1800"]}
;; {:tag :item :attributes {}
;; :content
;; [{:tag :title :attributes {} :content ["Example entry"]}
;; {:tag :description :attributes {} :content ["Here is some text containing an interesting description."]}
;; {:tag :link :attributes {} :content ["http://www.example.com/blog/post/1"]}
;; {:tag :guid :attributes {:isPermaLink "false"} :content ["7bd204c6-1655-4c27-aaaa-111111111111"]}
;; {:tag :pubDate :attributes {} :content ["Sun, 06 Sep 2009 16:20:00 +0000"]}]}
;; {:tag :item :attributes {}
;; :content
;; [{:tag :title :attributes {} :content ["Example entry2"]}
;; {:tag :description :attributes {} :content ["Here is some text containing an interesting description."]}
;; {:tag :link :attributes {} :content ["http://www.example.com/blog/post/2"]}
;; {:tag :guid :attributes {:isPermaLink "false"} :content ["7bd204c6-1655-4c27-aeee-53f933c5395f"]}
;; {:tag :pubDate :attributes {} :content ["Sun, 06 Sep 2009 16:20:00 +0000"]}]}]}]}
```

This data structure is fully compatible with the XML zipper inside `clojure.zip`

```
(require '[clojure.zip :as z])

(-> xml core/xml->clj
z/xml-zip
z/down
z/down
z/rightmost
z/node
:content
first)

;; => "Example entry2"
```

## License

Licensed under [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0)