Based on: Combining XML Languages by Sarah Coppin, Brent Hendricks
Summary: 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 http://cnx.org/content/m10159/latest/. 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言語を使用するドキュメントを、同時に書くことができます。