令人沮丧的问题与将xinclude/XPointer在这里。

目的是包括条目从名单XML格式的价格进入另一个文件。我有一个文件的列表的价格,看起来是这样的:

 <?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>

下面的包括失败

 <xi:include href="../listen/preise.xml#xpointer(/preise/preis[@id='foo100']/text())" />

 element include: XInclude error : failed build URL

现在,如果我改变格式的标识的价目表以专门的数值

 <?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>

和使用这种包括而不撇号

 <xi:include href="../listen/preise.xml#xpointer(/preise/preis[@id=100]/text())" />

突然一切工作。因此,这个问题似乎是相关撇号,但是我怎么得到的周围?

还有,这是我的xmllint版本信息:

 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
有帮助吗?

解决方案

将xinclude W3C的规格:

第十一:包括素有 如下属性:

href

值,经过适当 逃离(见4.1.1逃脱的href 属性值)已经执行, 结果在URI参考或IRI 参考指定位置 资源包括。Href 属性是可有可无的;没有的 这一属性是一样的 指定href="",即, 参考的是同样的文件。如果 href属性是不存在的时候 分析="xml",xpointer属性 必须存在。 片段 标识不应使用;他们 外观是一个致命的错误。 一个值 这一结果在语法上 无效URI或IRI应报告 作为一个致命的错误,但是一些 实现可找到它 不切实际的区分这种情况下 从资源的错误。

因此,"片段标识不应使用;他们的出现是一个致命的错误。"

解决方案:试图忽略的 href 属性和使用 xpointer 属性。

然而, 应注意的 以下案文 从同一规格:

支持[XPointer xpointer()方案]不是强制性的,完全将xinclude一致性。文的提交人已获通知,须提出利用xpointer()以及其他XPointer计划于元件()可能不是 支持通过所有符合的实现将xinclude

最后, 这里是一个例子,从规格 使用XPointer片段包含:

下面说明的结果,包括碎片的另一个XML文件。假设 base URI的文件 http://www.example.com/JoeSmithQuote.xml.

<?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>

price-list.xml 引用一DTD宣布id属性作为类型的ID,并包含:

<?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>

该信息集得到解决的内含物本文件是相同的(除了 包括历史和语言特性),作为下列文件:

<?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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top