Skip to content

hiccup-style input #6

@akond

Description

@akond

I frequently find myself utilizing hiccup-style data structures rather than strings/streams. Something like:

[:list
     [:token "defproject"]
     [:whitespace " "]...
   ]

In the past, I would convert it into a string and then perform my XSLT transformations. However, more recently, I crafted a straightforward wrapper around TinyBuilder.

(defn xml-document [tree]
    (let [processor     (Processor. false)
          configuration (.getUnderlyingConfiguration processor)
          builder       (TinyBuilder. (.makePipelineConfiguration configuration))
          walk          (fn walk [x]
                            (if (coll? x)
                                (do
                                    (.startElement builder (FingerprintedQName. "" "" (name (first x))) (Untyped/getInstance) ExplicitLocation/UNKNOWN_LOCATION 0)
                                    (run! walk (rest x))
                                    (.endElement builder))
                                (.characters builder x ExplicitLocation/UNKNOWN_LOCATION 0)))]
        (.open builder)
        (.startDocument builder 0)
        (walk tree)
        (.close builder)
        (.getRootNode (.getTree builder))))

At present, it does not have the capability to handle attributes.
Would you be interested in incorporating this code into your library once it is completed?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions