XML , XLink 및 XPointer
XLink는 XML 문서에 하이퍼링크를 만드는 데 사용됩니다.
|
XLink 브라우저 지원
XML 문서에는 XLink에 대한 브라우저 지원이 없습니다.
그러나 모든 주요 브라우저 는 SVG에서 XLink를 지원 합니다.
XLink 구문
HTML에서 <a> 요소는 하이퍼링크를 정의합니다. 그러나 이것은 XML에서 작동하는 방식이 아닙니다. XML 문서에서는 원하는 요소 이름을 사용할 수 있습니다. 따라서 브라우저가 XML 문서에서 호출될 링크 요소를 예측하는 것은 불가능합니다.
다음은 XLink를 사용하여 XML 문서에 링크를 만드는 방법에 대한 간단한 예입니다.
<?xml version="1.0" encoding="UTF-8"?>
<homepages xmlns:xlink="http://www.w3.org/1999/xlink">
<homepage xlink:type="simple"
xlink:href="https://www.w3schools.com">Visit W3Schools</homepage>
<homepage xlink:type="simple"
xlink:href="http://www.w3.org">Visit W3C</homepage>
</homepages>
XLink 기능에 액세스하려면 XLink 네임스페이스를 선언해야 합니다. XLink 네임스페이스는 "http://www.w3.org/1999/xlink"입니다.
<homepage> 요소의 xlink:type 및 xlink:href 속성은 XLink 네임스페이스에서 가져옵니다.
xlink:type="simple"은 간단한 "HTML과 유사한" 링크를 만듭니다("여기를 클릭하여 거기로 이동"을 의미).
xlink:href 속성은 연결할 URL을 지정합니다.
XLink 예제
다음 XML 문서에는 XLink 기능이 포함되어 있습니다.
<?xml version="1.0" encoding="UTF-8"?>
<bookstore xmlns:xlink="http://www.w3.org/1999/xlink">
<book title="Harry Potter">
<description
xlink:type="simple"
xlink:href="/images/HPotter.gif"
xlink:show="new">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
</description>
</book>
<book title="XQuery Kick Start">
<description
xlink:type="simple"
xlink:href="/images/XQuery.gif"
xlink:show="new">
XQuery Kick Start delivers a concise introduction
to the XQuery standard.......
</description>
</book>
</bookstore>
설명된 예:
- XLink 네임스페이스는 문서 상단에 선언됩니다(xmlns:xlink="http://www.w3.org/1999/xlink").
- xlink:type="simple"은 간단한 "HTML과 유사한" 링크를 생성합니다.
- xlink:href 속성은 연결할 URL을 지정합니다(이 경우 - 이미지).
- xlink:show="new"는 링크가 새 창에서 열리도록 지정합니다.
XLink - 더 나아가
위의 예에서 우리는 간단한 XLink를 보여주었습니다. XLink는 독립형 페이지 대신 리소스로 원격 위치에 액세스할 때 점점 더 흥미로워지고 있습니다.
xlink:show 속성 값을 "embed"로 설정하면 연결된 리소스가 페이지 내에서 인라인으로 처리되어야 합니다. 예를 들어 이것이 또 다른 XML 문서일 수 있다고 생각하면 XML 문서의 계층 구조를 작성할 수 있습니다.
xlink:actuate 속성을 사용하여 리소스가 표시되어야 하는 시간을 지정할 수도 있습니다.
XLink 속성 참조
Attribute | Value | Description |
---|---|---|
xlink:actuate | onLoad onRequest other none |
Defines when the linked resource is read and shown:
|
xlink:href | URL | Specifies the URL to link to |
xlink:show | embed new replace other none |
Specifies where to open the link. Default is "replace" |
xlink:type | simple extended locator arc resource title none |
Specifies the type of link |
엑스포인터
|
XPointer 브라우저 지원
XPointer에 대한 브라우저 지원은 없습니다. 그러나 XPointer는 다른 XML 언어에서 사용됩니다.
XPointer 예제
이 예에서는 XLink와 함께 XPointer를 사용하여 다른 문서의 특정 부분을 가리킵니다.
대상 XML 문서(링크하려는 문서)부터 살펴보겠습니다.
<?xml version="1.0" encoding="UTF-8"?>
<dogbreeds>
<dog breed="Rottweiler" id="Rottweiler">
<picture url="https://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="https://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>
위의 XML 문서는 각 요소에 id 속성을 사용합니다!
따라서 XLink와 마찬가지로 전체 문서에 연결하는 대신 XPointer를 사용하면 문서의 특정 부분에 연결할 수 있습니다. 페이지의 특정 부분에 연결하려면 xlink:href 속성의 URL 뒤에 xlink:href="https://dog.com/dogbreeds.xml"과 같이 숫자 기호(#)와 XPointer 표현식을 추가하세요. #xpointer(id('로트와일러'))". 표현식은 id 값이 "Rottweiler"인 대상 문서의 요소를 참조합니다.
XPointer는 또한 id가 있는 요소에 연결하기 위한 약식 방법을 허용합니다. xlink:href="https://dog.com/dogbreeds.xml#Rottweiler"와 같이 id 값을 직접 사용할 수 있습니다.
다음 XML 문서에는 각 개 품종에 대한 추가 정보에 대한 링크가 포함되어 있습니다.
<?xml version="1.0" encoding="UTF-8"?>
<mydogs xmlns:xlink="http://www.w3.org/1999/xlink">
<mydog>
<description>
Anton is my favorite dog. He has won a lot of.....
</description>
<fact xlink:type="simple" xlink:href="https://dog.com/dogbreeds.xml#Rottweiler">
Fact about Rottweiler
</fact>
</mydog>
<mydog>
<description>
Pluto is the sweetest dog on earth......
</description>
<fact xlink:type="simple" xlink:href="https://dog.com/dogbreeds.xml#FCRetriever">
Fact about flat-coated Retriever
</fact>
</mydog>
</mydogs>