API for clojure.data.xml - Lazy XML parsing 0.0.9 (in development)

by Chris Houser

Full namespace name: clojure.data.xml

Overview

Functions to parse XML into lazy sequences and lazy trees and
emit these as text.

Protocols



AsElements

Protocol

    Known implementations: clojure.lang.IPersistentVector, clojure.lang.ISeq, clojure.lang.Keyword, java.lang.String, nil, Object
    

as-elements

function
Usage: (as-elements expr)
Return a seq of elements represented by an expression.
Source


EventGeneration

Protocol
Protocol for generating new events based on element type
Known implementations: clojure.data.xml.CData, clojure.data.xml.Comment, clojure.data.xml.Element, clojure.data.xml.Event, clojure.lang.Sequential, java.lang.Boolean, java.lang.Number, java.lang.String, nil

gen-event

function
Usage: (gen-event item)
Function to generate an event for e.

next-events

function
Usage: (next-events item next-items)
Returns the next set of events that should occur after e.  next-events are the
events that should be generated after this one is complete.
Source

Types



CData

record

    Fields: [content]
Protocols:
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map


Comment

record

    Fields: [content]
Protocols:
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map


Element

record

    Fields: [tag attrs content]
Protocols:
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map


Event

record

    Fields: [type name attrs str]
Protocols:
Interfaces: clojure.lang.IHashEq, clojure.lang.IKeywordLookup, clojure.lang.ILookup, clojure.lang.IObj, clojure.lang.IPersistentMap, java.io.Serializable, java.util.Map

Public Variables and Functions



->CData

function
Usage: (->CData content)
Positional factory function for class clojure.data.xml.CData.
Source


->Comment

function
Usage: (->Comment content)
Positional factory function for class clojure.data.xml.Comment.
Source


->Element

function
Usage: (->Element tag attrs content)
Positional factory function for class clojure.data.xml.Element.
Source


->Event

function
Usage: (->Event type name attrs str)
Positional factory function for class clojure.data.xml.Event.
Source


emit

function
Usage: (emit e stream & {:as opts})
Prints the given Element tree as XML text to stream.
Options:
 :encoding <str>          Character encoding to use
Source


emit-str

function
Usage: (emit-str e)
Emits the Element to String and returns it
Source


event-tree

function
Usage: (event-tree events)
Returns a lazy tree of Element objects for the given seq of Event
objects. See source-seq and parse.
Source


indent

function
Usage: (indent e stream & {:as opts})
Emits the XML and indents the result.  WARNING: this is slow
it will emit the XML and read it in again to indent it.  Intended for
debugging/testing only.
Source


indent-str

function
Usage: (indent-str e)
Emits the XML and indents the result.  Writes the results to a String and returns it
Source


map->CData

function
Usage: (map->CData m#)
Factory function for class clojure.data.xml.CData, taking a map of keywords to field values.
Source


map->Comment

function
Usage: (map->Comment m#)
Factory function for class clojure.data.xml.Comment, taking a map of keywords to field values.
Source


map->Element

function
Usage: (map->Element m#)
Factory function for class clojure.data.xml.Element, taking a map of keywords to field values.
Source


map->Event

function
Usage: (map->Event m#)
Factory function for class clojure.data.xml.Event, taking a map of keywords to field values.
Source


parse

function
Usage: (parse source & props)
Parses the source, which can be an
InputStream or Reader, and returns a lazy tree of Element records. Accepts key pairs
with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html
and xml-input-factory-props for more information. Defaults coalescing true.
Source


parse-str

function
Usage: (parse-str s & props)
Parses the passed in string to Clojure data structures.  Accepts key pairs
with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html
and xml-input-factory-props for more information. Defaults coalescing true.
Source


seq-tree

function
Usage: (seq-tree parent exit? node coll)
Takes a seq of events that logically represents
a tree by each event being one of: enter-sub-tree event,
exit-sub-tree event, or node event.

Returns a lazy sequence whose first element is a sequence of
sub-trees and whose remaining elements are events that are not
siblings or descendants of the initial event.

The given exit? function must return true for any exit-sub-tree
event.  parent must be a function of two arguments: the first is an
event, the second a sequence of nodes or subtrees that are children
of the event.  parent must return nil or false if the event is not
an enter-sub-tree event.  Any other return value will become
a sub-tree of the output tree and should normally contain in some
way the children passed as the second arg.  The node function is
called with a single event arg on every event that is neither parent
nor exit, and its return value will become a node of the output tree.

(seq-tree #(when (= %1 :<) (vector %2)) #{:>} str
          [1 2 :< 3 :< 4 :> :> 5 :> 6])
;=> (("1" "2" [("3" [("4")])] "5") 6)
Source


sexp-as-element

function
Usage: (sexp-as-element sexp)
Convert a single sexp into an Element
Source


sexps-as-fragment

function
Usage: (sexps-as-fragment)
       (sexps-as-fragment sexp)
       (sexps-as-fragment sexp & sexps)
Convert a compact prxml/hiccup-style data structure into the more formal
tag/attrs/content format. A seq of elements will be returned, which may
not be suitable for immediate use as there is no root element. See also
sexp-as-element.

The format is [:tag-name attr-map? content*]. Each vector opens a new tag;
seqs do not open new tags, and are just used for inserting groups of elements
into the parent tag. A bare keyword not in a vector creates an empty element.

To provide XML conversion for your own data types, extend the AsElements
protocol to them.
Source


source-seq

function
Usage: (source-seq s & {:as props})
Parses the XML InputSource source using a pull-parser. Returns
a lazy sequence of Event records.  Accepts key pairs
with XMLInputFactory options, see http://docs.oracle.com/javase/6/docs/api/javax/xml/stream/XMLInputFactory.html
and xml-input-factory-props for more information.
Defaults coalescing true and supporting-external-entities false.
Source
Logo & site design by Tom Hickey.
Clojure auto-documentation system by Tom Faulhaber.