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="http://dog.com/rottweiler.gif" />
  <history>
  Rottweiler의 조상은大概 로마인
  drover dogs.....
  </history>
  <temperament>
  Confident, bold, alert and imposing, the Rottweiler
  보호 능력으로 인해 인기가 많은 선택입니다...
  </temperament>
</dog>
<dog breed="FCRetriever" id="FCRetriever">
  <picture url="http://dog.com/fcretriever.gif" />
  <history>
  retrieving dogs의 가장 오래된 사용 중 하나는
  어부들이 물에서 물고기를 가져오는 도움을 합니다...
  </history>
  <temperament>
  평평한 머리카락의 retrieves는 맛있고 활기차게:
  뛰어난 에너지와 놀이와 retrieves를 사랑하는 개.
  </temperament>
</dog>
</dogbreeds>

브라우저에서 "dogbreeds.xml" 파일을 확인하세요

주의사항:위의 XML 문서는 링크할 필요가 있는 각 요소에 id 속성을 사용했습니다!

XML 링크 문서

전체 문서로 링크할 수 있는 것 이상으로, XPointer는 문서의 특정 부분으로 링크할 수 있습니다. 페이지의 특정 부분에 링크하려면, xlink:href 속성의 URL 뒤에 한 hash(#)와 XPointer 표현식을 추가하세요.

표현식:#xpointer(id("Rottweiler")) 목표 문서에서 "Rottweiler" 값이 있는 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">
  안톤은 제가 가장 좋아하는 개입니다. 그는 많은.....를 이겼습니다.
  </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">
  플루토는 지구상에서 가장 맛있는 개입니다......
  </description>
</mydog>
</mydogs>