如何使用 xpath 查找根元素名称

how to find the root elements name using xpath

您好,我有一个 XML 文件,我必须使用 xpath 找到它的根元素,我正在使用 mule ESB,所以我需要将这个根元素设置为变量,这样任何人都可以为我提供 xpath 来查找名称根元素

这应该有效。

name(/*)

样本XML

<the>
    <element>hello</element>
</the>

结果

the

在 mule 中,您可以将 MEL 表达式定义为

#[xpath:name(/*)]

检索根元素

正确的 MEL 表达式是 #[xpath('xpath:name(/*)')]

其他答案帮助我找到了正确的 answer.Thanks all

由于 xpath 已被弃用,因此应改用 xpath3。

梅尔示例:#[xpath3('name(/*)')]