Latest web development tutorials

ตัวอย่าง XPointer

ลองมาศึกษาตัวอย่างที่จะเรียนรู้บางไวยากรณ์ XPointer พื้นฐาน


ตัวอย่าง XPointer

ในตัวอย่างนี้เราจะแสดงวิธีการใช้และ XPointer XLink ให้ชี้ไปที่บางชุดอื่น ๆ ของเฉพาะส่วนของเอกสาร

เราจะเริ่มต้นโดยการศึกษาเอกสารเป้าหมาย XML (นั่นคือเราต้องการที่จะเชื่อมโยงไปยังเอกสารที่)


เอกสาร XML เป้าหมาย

กำหนดเป้าหมายเอกสาร XML ชื่อ "dogbreeds.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>