Apache Digester 模式:需要 XSLT 之类的东西。或“current()”

发布于 2024-12-10 00:54:01 字数 1463 浏览 0 评论 0原文

我正在尝试使用 Apache Digester (V3) 处理包含“线程转储”的 XML 文件:因此文件包含许多线程转储,一个线程转储包含许多线程,一个线程包含一个堆栈跟踪,其中包含许多行

像这样:(简化)

<threaddumps>
<threaddump name="xxx">
<thread name="thread-1">
<stacktrace>
<line>
java.lang.wait
</line>
<line>
...
</line>
</stacktrace>
</thread>
<thread name="thread-2">
...
</threaddump>
<threaddump name="yyy">
...
</threaddumps>

我正在使用基于 XML 的规则来处理此输入文件;下面的片段:

<pattern value="thread">
                <object-create-rule classname="mypackagemodel.Thread"/>
                <set-next-rule methodname="addThread" paramtype="mypackagemodel.Thread"/>
                <set-properties-rule>
                    <alias attr-name="name" prop-name="name" />
                </set-properties-rule>
                <pattern value="stacktrace/line">
                        <object-create-rule classname="mypackagemodel.StackLine"/>
                        <set-next-rule methodname="addStackLine" paramtype="mypackagemodel.StackLine"/>
                        <!-- need something here -->
                </pattern>  
</pattern>

如何从“line”标签之间提取该文本?我已经在“stacktrace/line”上进行匹配,没有可以使用的子元素 - 那么我可以使用什么模式?

另一种说法 - 'StackLine' 对象正在被创建并正确关联 - 只是我不知道用什么来调用我的 'setName()' 设置器?

(例如,在 XSLT 中,在类似情况下通常会使用“.”或“current()”)

I'm trying to use Apache Digester (V3) to process an XML file which contains 'thread-dumps' : so file contains many thread-dumps, one thread-dump contains many threads, and one thread contains a stacktrace, which consists of many lines

Like this: (Simplified)

<threaddumps>
<threaddump name="xxx">
<thread name="thread-1">
<stacktrace>
<line>
java.lang.wait
</line>
<line>
...
</line>
</stacktrace>
</thread>
<thread name="thread-2">
...
</threaddump>
<threaddump name="yyy">
...
</threaddumps>

I am using a XML-based rule to process this input file; fragment below:

<pattern value="thread">
                <object-create-rule classname="mypackagemodel.Thread"/>
                <set-next-rule methodname="addThread" paramtype="mypackagemodel.Thread"/>
                <set-properties-rule>
                    <alias attr-name="name" prop-name="name" />
                </set-properties-rule>
                <pattern value="stacktrace/line">
                        <object-create-rule classname="mypackagemodel.StackLine"/>
                        <set-next-rule methodname="addStackLine" paramtype="mypackagemodel.StackLine"/>
                        <!-- need something here -->
                </pattern>  
</pattern>

How do I pull that text out from the in between 'line' tags though ? I'm already matching on 'stacktrace/line', there is no sub-element to use - so what pattern can I use ?

Another way of putting it - The 'StackLine' object is being created and associated correctly - its just that I don't know what to call my 'setName()' setter with ?

(In XSLT one would generally use '.' or 'current()' in a similar scenario for instance)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看透却不说透 2024-12-17 00:54:01

明白了:显然一个空的模式字符串将匹配当前节点的文本:

这对我有用:

<bean-property-setter-rule pattern="" propertyname="line"/>

Got it : apparently an empty pattern string will match the current node's text:

This worked for me:

<bean-property-setter-rule pattern="" propertyname="line"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文