首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在寻址撇号包含的@id值时未解析XPointer URL

在寻址撇号包含的@id值时未解析XPointer URL
EN

Stack Overflow用户
提问于 2010-11-19 21:56:26
回答 1查看 963关注 0票数 3

关于XInclude / XPointer的令人沮丧的问题。

其目的是将XML格式的价格条目列表中的条目包含到另一个文档中。我有一个包含价格列表的文档,如下所示:

代码语言:javascript
复制
 <?xml version="1.0" encoding="iso-8859-1"?>
 <!DOCTYPE preise [
   <!ELEMENT preise (preis+)>
   <!ELEMENT preis (#PCDATA)>
   <!ATTLIST preis id ID #REQUIRED>
 ]>
 <preise>
   <preis id="a0">./.</preis>
 <preis id='foo100'>136,10</preis>
 <preis id='foo101'>163,32</preis>
 </preise>

以下包含失败

代码语言:javascript
复制
 <xi:include href="../listen/preise.xml#xpointer(/preise/preis[@id='foo100']/text())" />

使用

代码语言:javascript
复制
 element include: XInclude error : failed build URL

现在,如果我将价目表中ids的格式更改为纯数字格式

代码语言:javascript
复制
 <?xml version="1.0" encoding="iso-8859-1"?>
 <!DOCTYPE preise [
   <!ELEMENT preise (preis+)>
   <!ELEMENT preis (#PCDATA)>
   <!ATTLIST preis id ID #REQUIRED>
 ]>
 <preise>
   <preis id="a0">./.</preis>
 <preis id='100'>136,10</preis>
 <preis id='101'>163,32</preis>
 </preise>

并使用不带撇号的include

代码语言:javascript
复制
 <xi:include href="../listen/preise.xml#xpointer(/preise/preis[@id=100]/text())" />

突然间,一切都正常了。所以这个问题似乎与撇号有关,但是我如何解决这个问题呢?

另外,下面是我的xmllint版本信息:

代码语言:javascript
复制
 xmllint: using libxml version 20706
    compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 FTP HTTP DTDValid HTML Legacy C14N Catalog XPath XPointer XInclude Iconv ISO8859X Unicode Regexps Automata Expr Schemas Schematron Modules Debug Zlib
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-20 05:25:42

来自 的

包含xi:

元素具有以下属性:

href

一个值,在执行了适当的转义(请参阅href属性值的4.1.1转义)后,会产生一个URI引用或IRI引用,指定要包含的资源的位置。href属性是可选的;如果没有此属性,则与指定href="“相同,也就是说,引用是对同一文档的引用。如果在parse="xml“时缺少href属性,则必须存在xpointer属性。不能使用片段标识符;它们的出现是致命错误。导致语法上无效的URI或IRI值应报告为致命错误,但某些实现可能会发现将这种情况与资源错误区分开来是不切实际的。

因此,“不能使用片段标识符;它们的出现是一个致命错误。”

解决方案:尝试省略href属性并使用xpointer属性。

然而,,请注意同一规范中的:

对于完全符合XInclude的

,对XPointer xpointer()方案的XInclude支持不是强制性的。作者被告知,并非所有符合规范的XInclude实现都支持使用xpointer()和除element()以外的其他XPointer方案

最后,使用XPointer片段包含的:

下面说明了包含另一个

文档的片段的结果。假设文档的基URI是http://www.example.com/JoeSmithQuote.xml

代码语言:javascript
复制
<?xml version='1.0'?>
<price-quote xmlns:xi="http://www.w3.org/2001/XInclude">
  <prepared-for>Joe Smith</prepared-for>
  <good-through>20040930</good-through>
  <xi:include href="price-list.xml" xpointer="w002-description"/>
  <volume>40</volume>
  <xi:include href="price-list.xml" xpointer="element(w002-prices/2)"/>
</price-quote>

价格列表.xml引用了一个将ID属性声明为类型id的DTD,并包含:

代码语言:javascript
复制
<?xml version='1.0'?>
<!DOCTYPE price-list SYSTEM "price-list.dtd">
<price-list xml:lang="en-us">
  <item id="w001">
    <description id="w001-description">
      <p>Normal Widget</p>
    </description>
    <prices id="w001-prices">
      <price currency="USD" volume="1+">39.95</price>
      <price currency="USD" volume="10+">34.95</price>
      <price currency="USD" volume="100+">29.95</price>
    </prices>
  </item>
  <item id="w002">
    <description id="w002-description">
      <p>Super-sized widget with bells <i>and</i> whistles.</p>
    </description>
    <prices id="w002-prices">
      <price currency="USD" volume="1+">59.95</price>
      <price currency="USD" volume="10+">54.95</price>
      <price currency="USD" volume="100+">49.95</price>
    </prices>
  </item>
</price-list>

在此文档上解析包含项所产生的信息集(包含历史记录和语言属性除外)与以下文档的信息集相同:

代码语言:javascript
复制
<?xml version='1.0'?>
<price-quote xmlns:xi="http://www.w3.org/2001/XInclude">
  <prepared-for>Joe Smith</prepared-for>
  <good-through>20040930</good-through>
  <description id="w002-description" xml:lang="en-us"
               xml:base="http://www.example.com/price-list.xml">
    <p>Super-sized widget with bells <i>and</i> whistles.</p>
  </description>
  <volume>40</volume>
  <price currency="USD" volume="10+" xml:lang="en-us"
         xml:base="http://www.example.com/price-list.xml">54.95</price>
</price-quote>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4225639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档