【发布时间】:2009-05-02 20:03:23
【问题描述】:
如果预定义的模式 //authorize 与以下 xml sn-p 中的元素匹配,我正在使用 dom4j 的规则 API 来触发操作。
<authorize role_required="admin">
<node title="node which is visible only to admin" path="" >
<authorize role_required="admin">
<node title="node which is visible only to admin" path=""/>
</authorize>
<authorize role_required="admin">
<node title="node which is visible only to admin" path="">
<authorize role_required="admin">
</authorize>
<node title="node which is visible only to admin" path=""/>
</node>
</authorize>
</node>
</authorize>
<authorize role_deny="admin">
<node title="Node which is not visible to admin" path=""/>
</authorize>
不幸的是,它似乎不适用于嵌套元素,只能找到第一级的授权元素。该动作仅触发两次,但有 5 个授权元素。 有人知道如何解决这个问题吗? 提前致谢。
我尝试将授权标签与以下规则匹配:
Rule authorizationRule = new Rule();
authorizationRule.setPattern( DocumentHelper.createPattern( "//authorize" ) );
authorizationRule.setAction( new AuthorizationRule() );
this.stylesheet = new Stylesheet();
this.stylesheet.addRule(authorizationRule);
this.stylesheet.run(document);
规则在第一层的元素上匹配两次。 我用 document.selectNodes 方法交叉检查了 XPath 模式,得到了所有五个元素。
【问题讨论】:
-
你能用一些示例代码附加这个问题吗?您究竟是如何尝试匹配
元素的? (听起来你的 XPath 有点不对劲,但从提供的信息中很难说。)