Latest web development tutorials

XPointerの例

それでは、いくつかの基本的なXPointerの構文を学習する例を検討してみましょう。


XPointerの例

この例では、文書の特定の部分のいくつかの他の組み合わせを指すようにするXPointerとXLinkのを使用する方法を紹介します。

我々は(我々はその文書にリンクする、つまり)ターゲットXML文書を研究することによって開始されます。


ターゲットXML文書

犬の異なる種類の数を示しています」dogbreeds.xml」という名前のXML文書を、ターゲット:

<?xml version="1.0" encoding="ISO-8859-1"?>

<dogbreeds>

<dog breed="Rottweiler" id="Rottweiler">
<picture url="../../dog.com/rottweiler.gif" />
<history>The Rottweiler's ancestors were probably Roman
drover dogs.....</history>
<temperament>Confident, bold, alert and imposing, the Rottweiler
is a popular choice for its ability to protect....</temperament>
</dog>

<dog breed="FCRetriever" id="FCRetriever">
<picture url="../../dog.com/fcretriever.gif" />
<history>One of the earliest uses of retrieving dogs was to
help fishermen retrieve fish from the water....</history>
<temperament>The flat-coated retriever is a sweet, exuberant,
lively dog that loves to play and retrieve....</temperament>
</dog>

</dogbreeds>

お使いのブラウザを参照してください"dogbreeds.xml」ファイルを

上記のXML文書は、我々はリンクを必要とする各要素にid属性を使用することに注意してください!


XMLドキュメントへのリンク

(XLinkの使用時)、文書全体よりにリンクすることができ、XPointerのは、ドキュメントの特定の部分にリンクすることができます。 XLINKで、ページの特定の部分にリンクするには:href属性をURLでシャープ記号(#)とのXPointer表現を追加した後。

式:#xpointer(ID(「ロットワイラーは" )) "ロットワイラー"要素の対象文書id値を参照することができます。

したがって、のxlink: このようなhref属性:のxlink:hrefの= "http://dog.com/dogbreeds.xml#xpointer(id('Rottweiler ' ))"

要素にリンクするIDを使用している場合しかし、XPointerが短縮形を許可します。 あなたはこのように、IDの直接の値を使用することができますのxlink:hrefの= "http://dog.com/dogbreeds.xml#Rottweiler" 。

次のXML文書がXLinkおよびXPointerので参照される各犬種の情報を参照することができます。

<?xml version="1.0" encoding="ISO-8859-1"?>

<mydogs xmlns:xlink="http://www.w3.org/1999/xlink">

<mydog xlink:type="simple"
xlink:href="http://dog.com/dogbreeds.xml#Rottweiler">
<description xlink:type="simple"
xlink:href="http://myweb.com/mydogs/anton.gif">
Anton is my favorite dog. He has won a lot of.....
</description>
</mydog>

<mydog xlink:type="simple"
xlink:href="http://dog.com/dogbreeds.xml#FCRetriever">
<description xlink:type="simple"
xlink:href="http://myweb.com/mydogs/pluto.gif">
Pluto is the sweetest dog on earth......
</description>
</mydog>

</mydogs>