how to use xpointer to link to specific node from another document

半世苍凉 提交于 2019-12-13 02:25:33

问题


I have two xml files. and I want to refer the value of a node from the other xml file.

example: 1.xml

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new society.</description>
   </book>
</catalog>

an 2.xml is

<?xml version="1.0" encoding="ISO-8859-1"?>
<doc xmlns:xi="http://www.w3.org/2003/XInclude">
<xi:include href="1.xml" xpointer="bk101"/>
</doc>

When I execute 2.xml, I get a error saying This XML file does not appear to have any style information associated with it. The document tree is shown below.

<doc><xi:include href="book.xml" xpointer="bk101"/></doc>

Can I get some help in resolving the issue.

Thanks


回答1:


Use a dummy stylesheet to resolve the error:

<?xml-stylesheet href="http://www.w3.org/StyleSheets/TR/W3C-REC.css"?>

Use a DTD to declare the ID attributes of the book elements as type ID:

<!ATTLIST book id ID #IMPLIED>

Save it as something like ids.dtd, then use a doctype in 1.xml to reference it:

<?xml version="1.0"?>
<!DOCTYPE id-list SYSTEM "ids.dtd">

References

  • xml:id Version 1.0
  • XInclude:Fragment Example
  • Associating Style Sheets with XML documents


来源:https://stackoverflow.com/questions/13550561/how-to-use-xpointer-to-link-to-specific-node-from-another-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!