Liking cljdoc? Tell your friends :D

eximia.core

A fast and small XML processor for Clojure. With XML namespace support and secure defaults.

Reads and writes a format similar but not identical to clojure.xml and data.xml:

  • Elements as maps with :tag, :attrs and :content keys
    • The :tag is represented as a javax.xml.namespace.QName to support XML namespaces.
    • :attrs is a map from QNames to strings, to support XML namespaces for the attribute names as well
    • :content is a seq of elements and character data
  • Character data as strings
    • By default, adjacent character sections (including CDATA) are joined together to one string when reading.

There are also options and utility functions to convert QNames to keywords when reading and from keywords to QNames when writing (:tag-fn and :key-fn, qname->keyword etc.).

CDATA blocks can also be read and written as CData records, processing instructions as ProcessingInstructions and comments as Comments.

A fast and small XML processor for Clojure. With XML namespace support and secure defaults.

Reads and writes a format similar but not identical to clojure.xml and data.xml:

* Elements as maps with `:tag`, `:attrs` and `:content` keys
    - The `:tag` is represented as a
      [`javax.xml.namespace.QName`](https://docs.oracle.com/javase/8/docs/api/javax/xml/namespace/QName.html)
      to support XML namespaces.
    - `:attrs` is a map from `QName`s to strings, to support XML namespaces for the attribute names as well
    - `:content` is a seq of elements and character data
* Character data as strings
    - By default, adjacent character sections (including CDATA) are joined together to one string when reading.

There are also options and utility functions to convert QNames to keywords when reading and from keywords to QNames
when writing (`:tag-fn` and `:key-fn`, [[qname->keyword]] etc.).

CDATA blocks can also be read and written as [[CData]] records, processing instructions as [[ProcessingInstruction]]s
and comments as [[Comment]]s.
raw docstring

CDataclj

source

Commentclj

source

Elementclj

source

input-factoryclj

(input-factory opts)

Create an XMLInputFactory. The opts map keys and values are the XMLInputFactory properties but :validating, :namespace-aware, :coalescing, :replacing-entity-references, :supporting-external-entities, :support-dtd, :reporter and :allocator can be used instead of the XMLInputFactory constants or the raw "javax.xml.stream.*" strings.

:support-dtd and :supporting-external-entities default to false to prevent XXE attacks.

Note that XMLInputFactory instances can be very expensive to create but are reusable. So call this as rarely as possible, probably only in the application startup phase.

Create an XMLInputFactory. The `opts` map keys and values are the
[XMLInputFactory properties](https://docs.oracle.com/javase/8/docs/api/javax/xml/stream/XMLInputFactory.html) but
`:validating`, `:namespace-aware`, `:coalescing`, `:replacing-entity-references`, `:supporting-external-entities`,
`:support-dtd`, `:reporter` and `:allocator` can be used instead of the XMLInputFactory constants or the raw
"javax.xml.stream.*" strings.

`:support-dtd` and `:supporting-external-entities` default to `false` to prevent
[XXE attacks](https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing).

Note that XMLInputFactory instances can be very expensive to create but are reusable. So call this as rarely as
possible, probably only in the application startup phase.
sourceraw docstring

keyword->qnameclj

(keyword->qname kw)

Convert the keyword kw to a QName, with the keyword namespace as the prefix (and NULL_NS_URI as the ns-uri).

Convert the keyword `kw` to a QName, with the keyword namespace as the prefix (and `NULL_NS_URI` as the ns-uri).
sourceraw docstring

local-nameclj

(local-name qname)

Get the local name string of a QName, similar to [[clojure.core/name]].

Get the local name string of a QName, similar to [[clojure.core/name]].
sourceraw docstring

ns-uriclj

(ns-uri qname)

Get the namespace URI string of a QName.

Get the namespace URI string of a QName.
sourceraw docstring

output-factoryclj

(output-factory opts)

Create an XMLOutputFactory. The opts map keys and values are the XMLOutputFactory properties but :repairing-namespaces can also be used instead of XMLOutputFactory/IS_REPAIRING_NAMESPACES or "javax.xml.stream.isRepairingNamespaces".

Note that XMLOutputFactory instances can be very expensive to create but are reusable. So call this as rarely as possible, probably only in the application startup phase.

Create an XMLOutputFactory. The `opts` map keys and values are the
[XMLOutputFactory properties](https://docs.oracle.com/javase/8/docs/api/javax/xml/stream/XMLOutputFactory.html)
but `:repairing-namespaces` can also be used instead of `XMLOutputFactory/IS_REPAIRING_NAMESPACES` or
`"javax.xml.stream.isRepairingNamespaces"`.

Note that XMLOutputFactory instances can be very expensive to create but are reusable. So call this as rarely as
possible, probably only in the application startup phase.
sourceraw docstring

prefixclj

(prefix qname)

Get the namespace prefix string of a QName, similar to [[clojure.core/namespace]].

Get the namespace prefix string of a QName, similar to [[clojure.core/namespace]].
sourceraw docstring

ProcessingInstructionclj

source

qnameclj

(qname local-name)
(qname ns-uri local-name)
(qname ns-uri local-name prefix)

Create a QName from a local name and optional namespace URI and prefix.

Create a QName from a local name and optional namespace URI and prefix.
sourceraw docstring

qname->keywordclj

(qname->keyword qname)

Convert the QName qname to a keyword, with the prefix as the keyword namespace.

Convert the QName `qname` to a keyword, with the prefix as the keyword namespace.
sourceraw docstring

qname->unq-keywordclj

(qname->unq-keyword qname)

Convert the QName qname to an unqualified keyword.

Convert the QName `qname` to an unqualified keyword.
sourceraw docstring

readclj

(read input)
(read input opts)

Read XML from input, which should be an InputStream or a Reader (or any ToStreamReader). Does not close input.

The optional opts map can have the following keys:

KeyDescriptionValueDefault
:tag-fnFunction to apply to tag QNamesAn IFnidentity
:key-fnFunction to apply to attribute key QNamesAn IFnidentity
:wrap-cdataReturn CDATA contents wrapped in CData instead of just the string.booleanfalse
:preserveReturn ProcessingInstructions and Comments instead of skipping them.A subset of #{:processing-instruction, :comment}#{}
:xml-input-factoryThe XMLInputFactory to use. See also input-factory.An XMLInputFactoryA (input-factory {:coalescing true}) cached internally in Eximia
Read XML from `input`, which should be an InputStream or a Reader (or any [[ToStreamReader]]).
Does not close `input`.

The optional `opts` map can have the following keys:

| Key                  | Description                                 | Value  | Default    |
|----------------------|---------------------------------------------|--------|------------|
| `:tag-fn`            | Function to apply to tag `QName`s           | An IFn | `identity` |
| `:key-fn`            | Function to apply to attribute key `QName`s | An IFn | `identity` |
| `:wrap-cdata`        | Return CDATA contents wrapped in [[CData]] instead of just the string. | boolean | `false` |
| `:preserve`          | Return [[ProcessingInstruction]]s and [[Comment]]s instead of skipping them. | A subset of `#{:processing-instruction, :comment}` | `#{}` |
| `:xml-input-factory` | The XMLInputFactory to use. See also [[input-factory]]. | An XMLInputFactory | A `(input-factory {:coalescing true})` cached internally in Eximia |
sourceraw docstring

read-strclj

(read-str input)
(read-str input opts)

Like read, but with a string as the input.

Like [[read]], but with a string as the `input`.
sourceraw docstring

ToStreamReadercljprotocol

Conversions to XMLStreamReader

Conversions to XMLStreamReader

-stream-readerclj

(-stream-reader self factory)

Wrap self into a XMLStreamReader, using the XMLInputFactory factory.

Wrap `self` into a XMLStreamReader, using the XMLInputFactory `factory`.
sourceraw docstring

ToStreamWritercljprotocol

Conversions to XMLStreamWriter

Conversions to XMLStreamWriter

-stream-writerclj

(-stream-writer self factory)

Wrap self into a XMLStreamWriter, using the XMLOutputFactory factory.

Wrap `self` into a XMLStreamWriter, using the XMLOutputFactory `factory`.
sourceraw docstring

writeclj

(write tree out)
(write tree out opts)

Write tree as XML to out, which should be an OutputStream or a Writer (or any ToStreamWriter). Does not close out.

The optional opts map can have the following keys:

KeyDescriptionValueDefault
:tag-fnFunction to convert tag names into QNamesAn IFnidentity
:key-fnFunction to convert attribute keys QNamesAn IFnidentity
:xml-versionThe XML standard to use"1.0" or "1.1""1.0"
:xml-output-factoryThe XMLOutputFactory to use. See also output-factory.An XMLOutputFactoryA (output-factory {:repairing-namespaces true}) cached internally in Eximia
Write `tree` as XML to `out`, which should be an OutputStream or a Writer (or any [[ToStreamWriter]]). Does not
close `out`.

The optional `opts` map can have the following keys:

| Key                   | Description                                 | Value                  | Default    |
|-----------------------|---------------------------------------------|------------------------|------------|
| `:tag-fn`             | Function to convert tag names into `QName`s | An IFn                 | `identity` |
| `:key-fn`             | Function to convert attribute keys `QName`s | An IFn                 | `identity` |
| `:xml-version`        | The XML standard to use                     | `"1.0"` or `"1.1"` | `"1.0"`  |
| `:xml-output-factory` | The XMLOutputFactory to use. See also [[output-factory]]. | An XMLOutputFactory | A `(output-factory {:repairing-namespaces true})` cached internally in Eximia |
sourceraw docstring

write-strclj

(write-str tree)
(write-str tree opts)

Like write, but returns a string instead of writing to a provided destination.

Like [[write]], but returns a string instead of writing to a provided destination.
sourceraw docstring

WriteXMLcljprotocol

Emitting an XML fragment

Emitting an XML fragment

-writeclj

(-write self out opts)

Write the XML fragment for self into the XMLStreamWriter out and write options opts.

Write the XML fragment for `self` into the XMLStreamWriter `out` and [[write]] options `opts`.
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close