[英]how to use xpointer to link to specific node from another document
我有兩個xml文件。 我想從另一個xml文件中引用節點的值。
示例: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>
2.xml是
<?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>
當我執行2.xml時,出現錯誤消息說此XML文件似乎沒有與之關聯的任何樣式信息。 文檔樹如下所示。
<doc><xi:include href="book.xml" xpointer="bk101"/></doc>
我可以得到一些解決問題的幫助。
謝謝
使用虛擬樣式表解決錯誤:
<?xml-stylesheet href="http://www.w3.org/StyleSheets/TR/W3C-REC.css"?>
使用DTD將book
元素的ID屬性聲明為ID類型:
<!ATTLIST book id ID #IMPLIED>
將其另存為ids.dtd
類的ids.dtd
,然后在1.xml
使用doctype 1.xml
進行引用:
<?xml version="1.0"?>
<!DOCTYPE id-list SYSTEM "ids.dtd">
參考文獻
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.