XMLチュートリアル

XMLホーム XMLの紹介 XML使用方法 XMLツリー XML構文 XML要素 XML属性 XML名前空間 XML表示 XML HttpRequest XMLパーサー XML DOM XML XPath XML XSLT XML XQuery XML XLink XMLバリデーター XML DTD XMLスキーマ XMLサーバー XMLの例 XMLクイズ XML証明書

XML AJAX

AJAXの紹介 AJAX XMLHttp AJAXリクエスト AJAX応答 AJAXXMLファイル AJAX PHP AJAX ASP AJAXデータベース AJAXアプリケーション AJAXの例

XML DOM

DOMの紹介 DOMノード DOMアクセス DOMノード情報 DOMノードリスト DOMトラバース DOMナビゲーション DOMは値を取得します DOM変更ノード DOM削除ノード DOM置換ノード DOM作成ノード DOM追加ノード DOMクローンノード DOMの例

XPathチュートリアル

XPathの概要 XPathノード XPath構文 XPath軸 XPath演算子 XPathの例

XSLTチュートリアル

XSLTの紹介 XSL言語 XSLT変換 XSLT <テンプレート> XSLT <値> XSLT <for-each> XSLT <ソート> XSLT <if> XSLT <選択> XSLT適用 クライアント上のXSLT サーバー上のXSLT XSLT Edit XML XSLTの例

XQueryチュートリアル

XQueryの紹介 XQueryの例 XQuery FLWOR XQuery HTML XQueryの用語 XQuery構文 XQuery追加 XQuery Select XQuery関数

XML DTD

DTDの紹介 DTDビルディングブロック DTD要素 DTD属性 DTD要素と属性 DTDエンティティ DTDの例

XSDスキーマ

XSDの概要 XSDハウツー XSD <スキーマ> XSD要素 XSD属性 XSDの制限

XSDコンプレックス

XSD要素 XSDが空です XSD要素のみ XSDテキストのみ XSD混合 XSDインジケーター XSD <任意> XSD <anyAttribute> XSD置換 XSDの例

XSDデータ

XSD文字列 XSD日付 XSD数値 XSDその他 XSDリファレンス

Webサービス

XMLサービス XML WSDL XML SOAP XML RDF XML RSS

参考文献

DOMノードタイプ DOMノード DOM NodeList DOM NamedNodeMap DOMドキュメント DOM要素 DOM属性 DOMテキスト DOM CDATA DOMコメント DOM XMLHttpRequest DOMパーサー XSLT要素 XSLT / XPath関数

XML 、XLink、XPointer


XLinkは、XMLドキュメントにハイパーリンクを作成するために使用されます。


XPath
  • XLinkは、XMLドキュメント内にハイパーリンクを作成するために使用されます
  • XMLドキュメント内の任意の要素がリンクとして動作できます
  • XLinkを使用すると、リンクファイルの外部でリンクを定義できます
  • XLinkはW3C勧告です

XLinkブラウザのサポート

XMLドキュメントでのXLinkのブラウザサポートはありません。

ただし、すべての主要なブラウザはSVGでXLinksをサポートしています。


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:
  • onLoad - the resource should be loaded and shown when the document loads
  • onRequest - the resource is not read or shown before the link is clicked
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

XPath
  • XPointerを使用すると、リンクでXMLドキュメントの特定の部分を指すことができます。
  • XPointerはXPath式を使用してXMLドキュメント内を移動します
  • XPointerはW3C勧告です

XPointerブラウザのサポート

XPointerのブラウザサポートはありません。ただし、XPointerは他のXML言語で使用されます。


XPointerの例

この例では、XPointerをXLinkと組み合わせて使用​​して、別のドキュメントの特定の部分をポイントします。

まず、ターゲット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の後に番号記号(#)とXPointer式を追加します。xlink:href = "https://dog.com/dogbreeds.xml #xpointer(id( 'Rottweiler')) "。この式は、ID値が「Rottweiler」のターゲットドキュメント内の要素を参照します。

XPointerでは、IDを持つ要素にリンクするための簡略化されたメソッドも使用できます。次のように、idの値を直接使用できます:xlink:href = "https://dog.com/dogbreeds.xml#Rottweiler"

次の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>