문제

Does anyone know if there is a straightforward way to serialize a parsed cyberneko ElementNSImpl object?

Here is my example in Clojure of serializing the whole DOM (an HTMLDocumentImpl object). This works, but I have not yet figured out how to do this for an element from the dom (ElementNSImpl).

(defn dom->xml
  [dom]
  (let [sw (java.io.StringWriter.)] 
    (.serialize 
     (org.apache.xml.serialize.XMLSerializer. 
      sw (org.apache.xml.serialize.OutputFormat. dom)) 
     dom)
    (.toString sw)))

Thanks, Rob

도움이 되었습니까?

해결책

This works for outputting XML, but I still don't know how to output HTML:

(defn dom->xml
  "serialize a dom element back to XML text"
  [elem]
  (let [sw (java.io.StringWriter.)]
    (.serialize
     (org.apache.xml.serialize.XMLSerializer. 
      sw (org.apache.xml.serialize.OutputFormat.))
     elem)
    (str sw)))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top