これを行うためにいくつかの異なるバージョンを使用していますが、すべてこのエラーが発生するようです:
[致命的なエラー] :1:171: プレフィックス「xmlns」は明示的に名前空間にバインドできません。「xmlns」の名前空間を任意のプレフィックスに明示的にバインドすることもできません。
私はhtmlを次のようにロードします:
// Load html file
def fis=new FileInputStream("2.html")
def html=new XmlSlurper(new org.cyberneko.html.parsers.SAXParser()).parseText(fis.text)
私が試したバージョン:
http://johnrellis.blogspot.com/2009/08/hmmm_04.html
import groovy.xml.StreamingMarkupBuilder
import groovy.xml.XmlUtil
def streamingMarkupBuilder=new StreamingMarkupBuilder()
println XmlUtil.serialize(streamingMarkupBuilder.bind{mkp.yield html})
http://old.nabble.com/How-to-print-XmlSlurper%27s-NodeChild-with-indentation--td16857110.html
// Output
import groovy.xml.MarkupBuilder
import groovy.xml.StreamingMarkupBuilder
import groovy.util.XmlNodePrinter
import groovy.util.slurpersupport.NodeChild
def printNode(NodeChild node) {
def writer = new StringWriter()
writer << new StreamingMarkupBuilder().bind {
mkp.declareNamespace('':node[0].namespaceURI())
mkp.yield node
}
new XmlNodePrinter().print(new XmlParser().parseText(writer.toString()))
}
何かアドバイス?
ありがとうございました!ミーシャ