Saxon Xpath 命名空间 [英] Saxon Xpath namespace

查看:62
本文介绍了Saxon Xpath 命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定以下 xml:

<Document xmlns="urn:company.com:catalog.01" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <book>
        <author>Wells</author>
    </book>
</Document>

使用 Xerces 可以执行以下 xpath 查询:

With Xerces the following xpath query works:

//urn:company.com:catalog.01:author

当我使用 Saxon (v 8.7) 时,出现一个带有消息无效 QName 本地部分 {company.com:catalog....}"的静态错误.

When I use Saxon (v 8.7) I a StaticError with message 'Invalid QName local part {company.com:catalog....}'.

Xpath 查询应该是什么样子来获取作者的值?

What should the Xpath query look like to get the value of author?

推荐答案

Xerces 不应允许像

Xerces should not allow an XPath expression like

//urn:company.com:catalog.01:author 

XPath 符合 XML 名称,因此 QName 中的 :(冒号)将前缀部分与 QName 的本地名称部分分开.

XPath is XML Names compliant, so a : (colon) in a QName divides the prefix part from local name part of a QName.

XPath 中没有在名称测试中使用完整扩展 QName 的语法:

There is no syntax in XPath to use the full expanded QName in name test:

你可以使用

//*[local-name()='author'][namespace-uri()='urn:company.com:catalog.01']

这篇关于Saxon Xpath 命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆