<< Chapter < Page Chapter >> Page >
This module explains how to use XML namespaces and DTDs to combine multiple XML languages in the same document.

This module contains Connexions documentation which is out-of-date. The contents of this module are provided here for historical purposes only and should not be considered accurate for the current version of the Connexions website. The current (English-language) version of this module can be located at (External Link) . If you have any additional questions or cannot find the answer to your question, please contact techsupport@cnx.org and we will be happy to assist in any way we can.

If you would like to assist Connexions by helping us update this module with an appropriate translation from the current English version, please contact us at cnx@cnx.org as we would appreciate your help with improving our support for non-English-speaking users.

  XML では、カスタムマークアップ言語でドキュメントを作成することができます。しかし、同じドキュメントで、複数の言語からのマークアップを結合したい場合、どうなるでしょうか?1つ以上のタグが、異なった意味で両方の言語に存在していたらどうなるでしょうか?例えば、あなたはHTMLに <table> タグを入力できます。機能を失うことなく、これらのタグをどのように使用しますか?

 解決策は、 ネームスペース (W3Cのサイトをみてください。 Namespaces in XML ))と呼ばれる拡張子をXMLで使用することです。ネームスペースは、特定のタグのセットとそれらの使用ルールに、Unique Global Identifier (URI)を関連付けます。特定のタグのためにネームスペースを宣言するには、ユニークな拡張子の値に xmlns 属性を設定してください。

 あなたはまたドキュメント内で使用するため、 ネームスペースの接頭語 を定義することができます。これをするには、 xmlns 属性の変更されたバージョンを使ってください。例えば、ネームスペースを示す http://somewhere.org/foo の、 foo という接頭語に関連付けるため、 xmlns:foo="http://somewhere.org/foo" のような属性を使うでしょう。そのときあなたは、適切な接頭語を加えることによって、そのネームスペースからどのタグが来るかを示すことができます。したがって、fooのネームスペースおける bar タグは <foo:bar> </foo:bar> のように書かれるでしょう。

 ディフォルトのネームスペースを使用すると、そのタグのどんな子も、同じネームスペースから来たと思われるでしょう。タグのすべての子に対してネームスペースが定義できます。特に ルートノード で使用するときに役に立ちます。

 CNXMLのバージョン0.5のためのネームスペース識別子は http://cnx.rice.edu/cnxml です。したがって、ドキュメントのディフォルトのネームスペースとして、CNXMLに申告するためには、 ドキュメント タグに属性を追加するでしょう。よって、MathMLのためのネームスペース識別子は http://www.w3.org/1998/Math/MathML 、だからMathMLネームスペースと接頭語 m を関連付けるには、 ドキュメント タグに xmlns:m="http://www.w3.org/1998/Math/MathML" という属性を追加してください。

 ネームスペースでは、同時に複数の言語でドキュメントを書くことができます。しかしながら、これらのドキュメントが有効であるように、それらはある言語のタグが、別の言語のタグの中に存在することを可能にする Document Type Definition (DTD)を持たなくてはなりません。よって、CNXMLドキュメントにMathMLを含めたいなら、MathMLがCNXMLタグ内に存在できるDTDが必要です。DTDがあれば、DOCTYPEを宣言できます。

 CNXMLのDOCTYPE宣言は以下の通りです。

<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_plain.dtd">

 CNXMLとMathMLのDOCTYPE宣言は以下の通りです。

<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">

 CNXMLとQMLのDOCTYPE宣言は以下の通りです。

<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus QML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_qml.dtd">

 CNXML、QML、およびMathMLのDOCTYPE宣言は以下の通りです。

<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML plus QML//EN""http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml_qml.dtd">

 CNXMLとMathMLを含む簡単なドキュメントです。CNXMLのネームスペースがディフォルトで、MathMLのネームスペースが接頭語 m を持っていることに注意してください。

<?xml version="1.0" standalone="no"?><!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd"><document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML". . .><metadata xmlns:md="http://cnx.rice.edu/mdml/0.4"><md:version>2.14</md:version><md:created>2005/08/24 15:08:34.203 GMT-5</md:created><md:revised>2005/08/24 15:09:19.244 GMT-5</md:revised><md:authorlist><md:author id="selc"><md:firstname>Sarah</md:firstname><md:surname>Coppin</md:surname><md:email>coppin@alumni.rice.edu</md:email></md:author><md:author id="brentmh"><md:firstname>Brent</md:firstname><md:othername>Michael</md:othername><md:surname>Hendricks</md:surname><md:email>brentmh@rice.edu</md:email></md:author><md:author id="takaryo"><md:firstname>Hironori</md:firstname><md:surname>Takaryo</md:surname><md:email>s043105@ishikawa-nct.ac.jp</md:email></md:author></md:authorlist><md:maintainerlist><md:maintainer id="takaryo"><md:firstname>Hironori</md:firstname><md:surname>Takaryo</md:surname><md:email>s043105@ishikawa-nct.ac.jp</md:email></md:maintainer></md:maintainerlist><md:keywordlist><md:keyword>DTD</md:keyword><md:keyword>namespace</md:keyword><md:keyword>tutorial</md:keyword><md:keyword>XML</md:keyword></md:keywordlist><md:abstract>This module explains how to use XML namespaces and DTDs to combine multiple XML languages in the same document.</md:abstract></metadata><content><para id='p1'>This math says "3y".<m:math display='inline'><m:apply><m:times/><m:cn>3</m:cn><m:ci>y</m:ci></m:apply></m:math></para></content></document>

 よって、ネームスペースの使用を結合することと、慎重に書かれたDTDによって、あなたは複数のXML言語を使用するドキュメントを、同時に書くことができます。

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Connexions tutorial and reference (japanese version). OpenStax CNX. Aug 26, 2005 Download for free at http://cnx.org/content/col10298/1.9
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Connexions tutorial and reference (japanese version)' conversation and receive update notifications?

Ask