我对clojure.data.xml有一些问题,因为在解析错误的 XML 时,抛出的异常没有被捕获。我发现运行时包装器可能存在一些问题,但是我尝试解开它的尝试没有成功,谁能向我指出为什么会发生这种情况?
(defn parse-xml-from-string
"takes in valid xml as a string and turns it into
#clojure.data.xml data, if bad xml returns false"
[xml]
(try
(do (parse (java.io.StringReader. xml)))
(catch javax.xml.stream.XMLStreamException e false)
(catch Exception ex
(cond (isa? (class (.getCause ex)) javax.xml.stream.XMLStreamException) false))))
方法调用
(viva-api.helpers.validation/parse-xml-from-string "<?xml version=\"1.0\"encoding=\"UTF-8\"?><foo><bar><baz>The baz value</baz></bar></foos>")
输出
#clojure.data.xml.Element{:tag :foo, :attrs {}, :content (user=> XMLStreamException ParseError at [row,col]:[1,84]
Message: The end-tag for element type "foo" must end with a '>' delimiter. com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next (XMLStreamReaderImpl.java:598)