<< Back to previous view

[DXML-18] Not parsing multiple top-level elements Created: 24/Jun/13  Updated: 10/Nov/13  Resolved: 10/Nov/13

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Alan Busby Assignee: Ryan Senior
Resolution: Declined Votes: 0
Labels: None
Environment:

[org.clojure/clojure "1.5.1"] and [org.clojure/data.xml "0.0.7"]



 Description   

(xml/parse-str "<a>1</a><b>2</b>")
Emits
{:tag :a, :attrs {}, :content ("1")}

Where did "b" go?



 Comments   
Comment by Alan Busby [ 24/Jun/13 7:43 AM ]

Sorry, feel free to close this.
Reviewing the code it appears that parse-str only accepts full XML documents and can't handle fragments, or is that incorrect?

Comment by Ryan Senior [ 10/Nov/13 10:39 PM ]

That's correct. Closing this as it's by design.





[DXML-23] Prefix is null in Inkscape SVG Created: 26/May/14  Updated: 19/Dec/15  Resolved: 19/Dec/15

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Christian Weilbach Assignee: Ryan Senior
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Ubuntu 14.04 amd64, openjdk-7, clojure 1.6.0, data.xml 0.0.7.



 Description   

When loading a fairly basic inkscape XML (1) in data.xml with (emit-str (parse (io/reader ".../minimal.svg"))), I get:

XMLStreamException Prefix cannot be null
com.sun.xml.internal.stream.writers.XMLStreamWriterImpl.writeAttribute (XMLStreamWriterImpl.java:575)
clojure.data.xml/write-attributes (xml.clj:39)
clojure.data.xml/emit-start-tag (xml.clj:50)
clojure.data.xml/emit-event (xml.clj:67)
clojure.data.xml/emit (xml.clj:367)
clojure.data.xml/emit-str (xml.clj:375)
xml-test.core/eval1512 (form-init517397699703209853.clj:1)
clojure.lang.Compiler.eval (Compiler.java:6703)
clojure.lang.Compiler.eval (Compiler.java:6666)
clojure.core/eval (core.clj:2927)
clojure.main/repl/read-eval-print-6625/fn-6628 (main.clj:239)
clojure.main/repl/read-eval-print--6625 (main.clj:239)

(1) https://gist.github.com/ghubber/34dbc54a9cf30ce68b8a



 Comments   
Comment by John Walker [ 13/Jun/14 9:26 PM ]

What is your system encoding?
Edit: Nevermind. It's specified in emit. Looks to be related to http://dev.clojure.org/jira/browse/DXML-4

Comment by Ryan Senior [ 19/Dec/15 9:33 AM ]

This is related to DXML-4. I have verified that your examples work in the new namespacing branch (which will soon be released as 0.1.0). Closing this as a duplicate of DXML-4.





[DXML-4] Namespaces support Created: 27/Mar/12  Updated: 13/Jan/16  Resolved: 13/Jan/16

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Carlo Sciolla Assignee: Ryan Senior
Resolution: Completed Votes: 12
Labels: None

Attachments: Text File add_namespaces.patch     Text File add-namespace-support.patch     Text File roundtrip-documents.patch    
Patch: Code and Test

 Description   

Add support for both parsing and emitting namespace qualified tags and namespaces URI declarations.
It basically follows the underlying Java XML API in giving xmlns:foo attributes "special" treatment.



 Comments   
Comment by Ryan Senior [ 22/May/12 10:26 AM ]

I don't see a contributor agreement for you Carlo. Have you signed one? http://clojure.org/contributing

Comment by Gary Trakhman [ 19/Jun/12 6:09 PM ]

ping, is the patch still waiting for a signed CA?

Comment by Ryan Senior [ 26/Jun/12 12:14 PM ]

Yes

Comment by Robert Onslow [ 01/Dec/12 5:07 AM ]

Is this patch due reasonable soon?

Comment by Andy Fingerhut [ 21/Apr/13 7:04 PM ]

Link to a design page with some ideas for XML namespace support in Clojure: http://dev.clojure.org/display/DXML/Fuller+XML+support

Comment by Herwig Hochleitner [ 26/Mar/14 9:20 AM ]

I've taken another stab at this. Attached roundtrip-documents.patch implements roundtripping, which means reading and writing xmlns attributes and namespaces as is.

Further improvements, that would fall into the scope of this ticket, but should be implemented on top of correct roundtripping, hence another ticket might be in order:

  • functionality for normalizing prefixes
  • rewriting prefixes
  • finding a minimal set of prefix names and/or default namespace, for given fragment
Comment by Steve Suehs [ 26/Mar/14 4:04 PM ]

I could really use this. I'm tweaking poms and the xml headers with schema locations cause grief. If you are in Austin I'll buy you a beer.

Comment by Herwig Hochleitner [ 01/Apr/14 4:41 AM ]

Good to hear that. I've implemented a walker to resolve names in namespaced xml and have the emitter assign the prefix of a resolved name. You can review / use at your own peril from here: https://github.com/bendlas/data.xml

Right now, I'm doing cleanup passes and trying to get feedback from the before pushing for change.

Comment by Paul Gearon [ 21/May/14 12:53 AM ]

I stupidly did this myself before realizing it was already done.
What is the current status? Still waiting on Carlo (since he's submitted a patch), looking to use Herwig's, or something else?

I wasn't totally happy with how I did it, since I used a binding for a parallel stack containing the current prefix->URI mappings. This was because QName prefixes are kept in the namespace of an element's keyword, but .writeStartElement and .writeAttribute need the URIs the prefix maps to, which wasn't being kept. It'd be nice to see if there's a better way.

Comment by Paul Gearon [ 21/May/14 10:36 AM ]

Submitting this patch, since the process requires a patch file. Carlo has not responded about the contributor agreement for 2 years, and none of the other attempts have been submitted as patches (edit: I've now seen Herwig's emails and realize that this is active).

Other implementations may be better, but I need to get the ball rolling on this.

Comment by Martin Clausen [ 27/Aug/14 2:35 PM ]

Carlo has signed a CA and is on the contributor list. Hope this means this much needed patch can be accpeted.

Comment by Thomas Engelschmidt [ 01/Nov/14 8:48 AM ]

Are there any plans on applying the patches ?

Comment by Ryan Senior [ 03/Nov/14 6:42 AM ]

We will be merging in Herwig's implementation soon. We're still waiting on getting him commit rights to the data.xml repo, so for now you can find his implementation here: https://github.com/bendlas/data.xml. We're planning on merging that into a namespaces branch where we'll hopefully have a beta release soon.

Comment by Christian Weilbach [ 25/May/15 8:37 AM ]

Any updates? This would probably resolve my problem as well: http://dev.clojure.org/jira/browse/DXML-23.

Comment by Joshua Griffith [ 16/Sep/15 10:41 AM ]

We ran into this problem when integrating with an external XML service. Are there any remaining barriers to this landing?

Comment by Ryan Senior [ 16/Sep/15 10:49 AM ]

Herwig is currently working on this in a fork (https://github.com/bendlas/data.xml), AFAIK his intention is to add it to data.xml once it's done

Comment by Joshua Griffith [ 12/Jan/16 7:53 PM ]

Is this closed? https://github.com/clojure/data.xml/commit/31558df7826fd388255bfe4c3b77ad4fbd8b89d1 suggests that it is.

Comment by Ryan Senior [ 13/Jan/16 8:43 AM ]

Correct, this was released as part of 0.1.0-beta1. Would love some feedback if you're using it.

Comment by Ryan Senior [ 13/Jan/16 8:43 AM ]

Released as 0.1.0-beta1





[DXML-28] pull-seq :characters events are not compatible with emit-event Created: 23/Sep/15  Updated: 13/Jan/16  Resolved: 13/Jan/16

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Nils Blum-Oeste Assignee: Ryan Senior
Resolution: Completed Votes: 0
Labels: None
Environment:

data.xml-0.0.8


Attachments: Text File fixbug_dxml-28.patch    

 Description   

`pull-seq` generates an event with type `:characters` for `XMLStreamConstants/CHARACTERS`. `emit-event` only handles events with type `:chars` though.

Because of that, emitting events from the event sequence created by `pull-seq` can fail with `IllegalArgumentException No matching clause: :characters clojure.data.xml/emit-event (xml.clj:66)`



 Comments   
Comment by Nils Blum-Oeste [ 23/Sep/15 6:41 AM ]

Working on a patch

Comment by Nils Blum-Oeste [ 23/Sep/15 7:00 AM ]

Patch attached

Comment by Nils Blum-Oeste [ 15/Dec/15 1:29 AM ]

Any comments on this @Ryan ?
Anything needed for this?

Comment by Ryan Senior [ 15/Dec/15 8:39 AM ]

Thanks for the ping Nils. I'm working with Herwig to get namespaces in a 0.1.0 release. I'll also take a look at this for inclusion in 0.1.0 as well, should be this week.

Comment by Ryan Senior [ 19/Dec/15 9:31 AM ]

I have verified that this issue is fixed in the namespacing branch. I validated the fix with a test and it will be released shortly. I'll close this ticket once the release has happened.

Comment by Ryan Senior [ 13/Jan/16 8:45 AM ]

Released as part of 0.1.0-beta1





[DXML-10] Support for DOCTYPE when emitting XML Created: 14/Nov/12  Updated: 28/Aug/16  Resolved: 28/Aug/16

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Major
Reporter: Thomas Greve Kristensen Assignee: Ryan Senior
Resolution: Completed Votes: 3
Labels: None

Attachments: Text File DXML-10-Add-support-for-doctype-declarations.patch     XML File web.xml    
Patch: Code and Test

 Description   

Some consumers of XML files require an explicit DOCTYPE to accept an XML file. data.xml does not currently support the specification of doctypes when emitting XML. When XML is parsed, I believe DOCTYPEs are silently ignored, so there is no representation in the data model for them. The best design is possibly an :doctype option in clojure.data.xml/emit ?

I've attached a web.xml as example.



 Comments   
Comment by Christian Egli [ 04/Jul/16 9:15 AM ]

Patch that adds support for doctype declarations when emitting XML

Comment by Christian Egli [ 23/Aug/16 7:41 AM ]

Is there anything I can do to move this issue forward? I have a local hack around this issue which prevents me from upgrading org.clojure/data.xml. OTOH I really need the new namespace support, so a new version containing both the namespace and the DOCTYPE support would be fantastic.

Thanks

Comment by Ryan Senior [ 28/Aug/16 1:31 PM ]

Thanks for the patch! This has been applied and will be included in beta2 (which will be released soon)





[DXML-30] Generate inconsistent namespace prefixes for subtrees, randomly omit namespace URIs in non-prefixed elements Created: 20/Jan/16  Updated: 28/Aug/16  Resolved: 28/Aug/16

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major
Reporter: Vlad Kozin Assignee: Ryan Senior
Resolution: Completed Votes: 1
Labels: bug

Attachments: Text File 0002-DXML-30-fix-emit-of-default-namespaces.patch    

 Description   
Unable to find source-code formatter for language: clojure. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
(xml/indent-str (xml/parse-str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
            <tradeDocument xmlns=\"http://www.fpml.org/FpML-5/confirmation\">
               <trade>Some trade</trade>
               <party>Party1</party>
               <party>Party2</party>
            </tradeDocument>"))

SAXParseException The prefix "b" for element "b:party" is not bound. com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse (AbstractSAXParser.java:1239)

To see clearly what's wrong:

Unable to find source-code formatter for language: clojure. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
(println (xml/emit-str (xml/parse-str "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
            <tradeDocument xmlns=\"http://www.fpml.org/FpML-5/confirmation\">
               <trade>Some trade</trade>
               <party>Party1</party>
               <party>Party2</party>
            </tradeDocument>")))

run through external formatter to see the problem

Unable to find source-code formatter for language: shell. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
$ pbpaste | xmllint --format - 
-:1: namespace error : Namespace prefix b on party is not defined
e xmlns:b="http://www.fpml.org/FpML-5/confirmation">Some trade</b:trade><b:party
                                                                               ^
-:1: namespace error : Namespace prefix b on party is not defined
l.org/FpML-5/confirmation">Some trade</b:trade><b:party>Party1</b:party><b:party
                                                                               ^
<?xml version="1.0" encoding="UTF-8"?>
<a:tradeDocument xmlns:a="http://www.fpml.org/FpML-5/confirmation" xmlns="http://www.fpml.org/FpML-5/confirmation">
  <b:trade xmlns:b="http://www.fpml.org/FpML-5/confirmation">Some trade</b:trade>
  <b:party>Party1</b:party>
  <b:party>Party2</b:party>
</a:tradeDocument>

Obvious problem here: no namespace URI is defined on <party> elements hence the error.

More general problem: input provided defines a default namespace so any non-prefixed tag is assumed to come from such namespace. I think a user can reasonably expect a roundtrip through parse/emit to not mess with that and preserve default namespace and therefore not introduce prefixes. Current behavior may not be wrong technically, but it is baffling and unexpected.



 Comments   
Comment by Herwig Hochleitner [ 04/Aug/16 2:36 PM ]

Fixed on top of 0001-DXML-33-fix-emit-of-generated-prefixes.patch

Comment by Ryan Senior [ 28/Aug/16 1:32 PM ]

The patch hs been applied and will be included in the 0.1.0-beta2 release.





[DXML-33] No XML namespace attribute emitted for namespaced sibling elements Created: 18/Jun/16  Updated: 28/Aug/16  Resolved: 28/Aug/16

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: David Bürgin Assignee: Ryan Senior
Resolution: Completed Votes: 0
Labels: None

Attachments: Text File 0001-DXML-33-fix-emit-of-generated-prefixes.patch    

 Description   

Following namespaced sibling elements don't get an XML namespace attribute when emitting XML using data.xml.

(xml/declare-ns
  :example.a "http://example.org/a"
  :example.b "http://example.org/b")

(def example-element
  (xml/sexp-as-element
    [:example.a/outer
     [:example.b/inner-1]
     [:example.b/inner-2]]))

Emitting example-element with emit-str results in the following invalid XML (reformatted):

<?xml version="1.0" encoding="UTF-8"?>
<a:outer xmlns:a="http://example.org/a">
  <b:inner-1 xmlns:b="http://example.org/b"></b:inner-1>
  <b:inner-2></b:inner-2>
</a:outer>

This issue may be related to DXML-30.



 Comments   
Comment by David Bürgin [ 18/Jun/16 12:11 PM ]

The work-around I found is to declare the prefixes for all namespace URIs in the root element:

(def example-element
  (xml/sexp-as-element
    [:example.a/outer
     {:xmlns/ea "http://example.org/a"
      :xmlns/eb "http://example.org/b"}
     [:example.b/inner-1]
     [:example.b/inner-2]]))

Perhaps also to consider in this issue: sometimes redundant XML namespace attributes are emitted, when they could be pulled up into a parent element instead.

(xml/emit-str
  (xml/sexp-as-element
    [:example.a/outer
     [:example.b/inner-1
      [:example.c/innermost-1]]
     [:example.c/inner-2]]))
<?xml version="1.0" encoding="UTF-8"?>
<a:outer xmlns:a="http://example.org/a">
  <b:inner-1 xmlns:b="http://example.org/b">
    <c:innermost-1 xmlns:c="http://example.org/c"></c:innermost-1>
  </b:inner-1>
  <d:inner-2 xmlns:d="http://example.org/c"></d:inner-2>
</a:outer>

Though to be sure this output is valid, so perhaps this part works as designed.

Comment by Herwig Hochleitner [ 04/Aug/16 5:16 AM ]

It works as designed. The emitter doesn't auto - pull-up namespaces, because that would require a second pass over the tree, while data.xml is designed to be stream-able. Use clojure.data.xml.process/aggregate-xmlns if you want that extra pass to clean up xmlns.

*EDIT* No, the sibling element part doesn't work as designed, investigating ...

Comment by Herwig Hochleitner [ 04/Aug/16 2:34 PM ]

I've fixed a bug in the emitter state handling, which I believe should fix the issue. Please try the attached patch.

Comment by David Bürgin [ 05/Aug/16 3:39 AM ]

Thank you. With the patch, the output is now valid:

<?xml version="1.0" encoding="UTF-8"?>
<a:outer xmlns:a="http://example.org/a">
  <b:inner-1 xmlns:b="http://example.org/b"></b:inner-1>
  <c:inner-2 xmlns:c="http://example.org/b"></c:inner-2>
</a:outer>
Comment by Ryan Senior [ 28/Aug/16 1:33 PM ]

The patch hs been applied and will be included in the 0.1.0-beta2 release.





[DXML-20] Odd behaviour when using lein uberjar Created: 25/Sep/13  Updated: 10/Nov/13  Resolved: 10/Nov/13

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Minor
Reporter: Neil Laurance Assignee: Ryan Senior
Resolution: Declined Votes: 0
Labels: None
Environment:

Leiningen 2.3.2 on Java 1.7.0_11 Java HotSpot(TM) 64-Bit Server VM



 Description   

(For original query posted to leiningen project, see: https://github.com/technomancy/leiningen/issues/1334)

I have a trivial app:

Unable to find source-code formatter for language: clojure. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
(ns test-app.core
  (:require [clojure.data.xml :as dx])
  (:gen-class))

(def xml
  (dx/emit-str
   (dx/sexp-as-element
    [:hello
     [:world]])))

(defn -main
  [& args]
  (println xml))

And a lein project definition of:

Unable to find source-code formatter for language: clojure. Available languages are: javascript, sql, xhtml, actionscript, none, html, xml, java
(defproject test-app "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [
    [org.clojure/clojure "1.5.1"]
    [org.clojure/data.xml "0.0.7"]]
  :main test-app.core
  :profiles {:uberjar {:aot :all}})

Attempting to run lein uberjar throws a stacktrace.

Attempting to run a second time without cleaning first succeeds.

Workaround is to change (def xml) to (defn xml []) and then invoke it.

Stacktrace is:

Warning: specified :main without including it in :aot. 
Implicit AOT of :main will be removed in Leiningen 3.0.0. 
If you only need AOT for your uberjar, consider adding :aot :all into your
:uberjar profile instead.
Compiling test-app.core
Exception in thread "main" java.lang.IllegalArgumentException: No implementation of method: :gen-event of protocol: #'clojure.data.xml/EventGeneration found for class: clojure.data.xml.Element, compiling:(core.clj:6:3)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3463)
    at clojure.lang.Compiler$DefExpr.eval(Compiler.java:408)
    at clojure.lang.Compiler.compile1(Compiler.java:7153)
    at clojure.lang.Compiler.compile(Compiler.java:7219)
    at clojure.lang.RT.compile(RT.java:398)
    at clojure.lang.RT.load(RT.java:438)
    at clojure.lang.RT.load(RT.java:411)
    at clojure.core$load$fn__5018.invoke(core.clj:5530)
    at clojure.core$load.doInvoke(core.clj:5529)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5336)
    at clojure.core$compile$fn__5023.invoke(core.clj:5541)
    at clojure.core$compile.invoke(core.clj:5540)
    at user$eval9.invoke(form-init6653146504522592512.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6619)
    at clojure.lang.Compiler.eval(Compiler.java:6609)
    at clojure.lang.Compiler.load(Compiler.java:7064)
    at clojure.lang.Compiler.loadFile(Compiler.java:7020)
    at clojure.main$load_script.invoke(main.clj:294)
    at clojure.main$init_opt.invoke(main.clj:299)
    at clojure.main$initialize.invoke(main.clj:327)
    at clojure.main$null_opt.invoke(main.clj:362)
    at clojure.main$main.doInvoke(main.clj:440)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)
Caused by: java.lang.IllegalArgumentException: No implementation of method: :gen-event of protocol: #'clojure.data.xml/EventGeneration found for class: clojure.data.xml.Element
    at clojure.core$_cache_protocol_fn.invoke(core_deftype.clj:541)
    at clojure.data.xml$fn__136$G__131__141.invoke(xml.clj:73)
    at clojure.data.xml$flatten_elements$fn__189.invoke(xml.clj:129)
    at clojure.lang.LazySeq.sval(LazySeq.java:42)
    at clojure.lang.LazySeq.seq(LazySeq.java:60)
    at clojure.lang.RT.seq(RT.java:484)
    at clojure.core$seq.invoke(core.clj:133)
    at clojure.data.xml$emit.doInvoke(xml.clj:366)
    at clojure.lang.RestFn.invoke(RestFn.java:425)
    at clojure.data.xml$emit_str.invoke(xml.clj:375)
    at clojure.lang.AFn.applyToHelper(AFn.java:161)
    at clojure.lang.AFn.applyTo(AFn.java:151)
    at clojure.lang.Compiler$InvokeExpr.eval(Compiler.java:3458)
    ... 27 more
Compilation failed: Subprocess failed


 Comments   
Comment by Ryan Senior [ 10/Nov/13 10:35 PM ]

I think this is a broader issue with AOT. I'm thinking it's probably related to this: http://dev.clojure.org/jira/browse/CLJ-979. I've seen this in other code, but it's the first time I've seen it reported for data.xml. Wrapping it in a function is a good idea. I think avoiding AOT would also fix your issue.





[DXML-31] Parsed events cannot be emitted Created: 28/Mar/16  Updated: 03/Oct/16  Resolved: 28/Aug/16

Status: Closed
Project: data.xml
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Trivial
Reporter: Hans Hübner Assignee: Ryan Senior
Resolution: Not Reproducible Votes: 0
Labels: None
Environment:

Clojure 1.7



 Description   

Events parsed with clojure.data.xml/source-seq cannot be serialized with clojure.data.xml/emit-event because the former puts characters parsed from XML elements into the `:characters` key of the events returned, but the latter expects them to be under the `:chars` key. I would propose that emit-event is changed so that it accepts both `:chars` and `:characters` as key for characters to be serialized, as that will provide the required backwards compatiblity.



 Comments   
Comment by Ryan Senior [ 28/Aug/16 1:35 PM ]

I believe this has been fixed when the namespace related changes came in. Try it again with 0.1.0-beta1 or higher and reopen if it's still an issue.

Comment by Hans Hübner [ 29/Aug/16 6:21 AM ]

Writing that it is "fixed" is a nice way of saying that the functionality has been removed altogether

Comment by Hans Hübner [ 12/Sep/16 4:49 AM ]

Just to follow up: I've found that due to the refactoring of clojure.data.xml into separate packages and the change of event representation to records, it was not apparently obvious how we could continue to use clojure.data.xml the way we did. We've now spent some more time reading the source code and found that the clojure.data.xml.tree, clojure.data.xml.jvm.emit and clojure.data.xml.event packages offer functionality that we require (incremental reading and writing of large XML documents). Can these packages and their exported functionality be considered part of the clojure.data.xml API?

Comment by Ryan Senior [ 12/Sep/16 9:10 AM ]

I think that's an intended use case. Could you attach something that's an example of how you're using it?

Comment by Hans Hübner [ 12/Sep/16 9:30 AM ]

Sure, one example is this package which we use to incrementally construct XML files:

(ns lambdawerk.xml-output
  (:require [clojure.data.xml :as xml]
            [clojure.data.xml.jvm.emit :as xml.jvm.emit]
            [clojure.data.xml.tree :as xml.tree]
            [clojure.data.xml.event :as xml.event]))

(def ^:dynamic *writer*)

(defn emit [element]
  (doseq [event (xml.tree/flatten-elements [element])]
    (xml.jvm.emit/emit-event event *writer*)))

(defmacro with-xml [stream & body]
  `(let [^javax.xml.stream.XMLStreamWriter writer# (-> (javax.xml.stream.XMLOutputFactory/newInstance)
                                                       (.createXMLStreamWriter ~stream))]
     (when (instance? java.io.OutputStreamWriter ~stream)
       (xml.jvm.emit/check-stream-encoding ~stream "UTF-8"))
     (.writeStartDocument writer# "UTF-8" "1.0")
     (let [result# (binding [*writer* writer#] ~@body)]
       (.writeEndDocument writer#)
       result#)))

(defmacro with-element [element & body]
  `(do (xml.jvm.emit/emit-event (xml.event/->StartElementEvent (name ~element) {} nil) *writer*)
       (let [result# (do ~@body)]
         (xml.jvm.emit/emit-event (xml.event/->EndElementEvent (name ~element)) *writer*)
         result#)))
Comment by Herwig Hochleitner [ 03/Oct/16 5:37 PM ]

Sorry, I just stumbled upon this (subscribing the RSS feed now).
My intention for refactoring was not to remove anything, but to make the project more browsable. I tried very hard to not change any functionality, and to finish the refactoring commits before the xmlns work. As you noticed already, all of the original functionality is available in various sub-namespaces and the various record types are not mandatory, but just for efficiency.
In particular, I'd never change anything in clojure.data.xml.tree, as it is an expression of the raw genius of Christophe Grand.





Generated at Sun Dec 04 08:38:40 CST 2016 using JIRA 4.4#649-r158309.