0

I am parsing a XML with Digester. A part of it contains content formatted in cryptic pseudo-HTML XML elements which I need to transform into an PDF. That will be done via Apache FOP. Hence I need to access the xml element which contains the content elements directly and pipe it to FOP. To do so the Digester FAQ states that one either

Wrap the nested xml in CDATA

or

If this can't be done then you need to use a NodeCreateRule to create a DOM node representing the body tag and its children, then serialise that DOM node back to text

Since it is a third party XML the CDATA approach could only be done via (another) XSLT which I hestitate to do.

It looks like this issue should be solvable via NodeCreateRule but I can not figure out how to get it done.

The documentation states that NodeCreateRule will push a Node onto the stack however I can only get it to pass null.

I tried

digester.addRule(docPath + "/contents", new NodeCreateRule());
digester.addCallMethod(docPath + "/contents", "setContentsXML");

setContentsXML expects a Element parameter.

I also tried this and this without any luck.

I am using the latest stable Digester. Would be thankful for any advice.

Update: I found the bug . The result on my system is null, too. I am using JDK 6u24

4

1 回答 1

0

我的问题以及链接的错误在于正确序列化Element. 在我的情况下,提到的 null 值不是由 Digester 返回,而是由Element#toString(). 我认为自 JDK 1.4 以来发生了一些变化。

通过错误示例:

result包含具有实际内容的另一个(文本)节点。然而 toString() 只是简单地获取它被称为 uppon 的 Element 实例的内容。元素树必须显式序列化。例如,在这个使用示例中的序列化方法NodeCreateRule

如果其他人试图将与 Digester 3 一起使用:您必须将方法签名更改SetSerializedNodeRule#end()SetSerializedNodeRule#end(String, String).

于 2012-01-05T07:45:55.027 回答