<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_plain.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" id="m10159">
  
  <name>Combining XML Languages</name>

  <metadata>
  <md:version>2.14</md:version>
  <md:created>2001/06/29</md:created>
  <md:revised>2004-04-19T19:09:52Z</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:authorlist>

  <md:maintainerlist>
    <md:maintainer id="mizar">
      <md:firstname>Christine</md:firstname>
      
      <md:surname>Donica</md:surname>
      <md:email>mizar@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="selc">
      <md:firstname>Sarah</md:firstname>
      
      <md:surname>Coppin</md:surname>
      <md:email>coppin@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="jenn">
      <md:firstname>Jenn</md:firstname>
      <md:othername>A.</md:othername>
      <md:surname>Drummond</md:surname>
      <md:email>jenn@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer 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:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>XML</md:keyword>
    <md:keyword>namespace</md:keyword>
    <md:keyword>DTD</md:keyword>
    <md:keyword>tutorial</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="namesp1">
      <link src="http://www.w3.org/XML">XML</link> allows you to
      create documents in custom markup languages.  But what if you
      want to combine markup from multiple languages in the same
      document?  What if there are one or more tags that exist in both
      languages, but with different meanings?  You could, for example, have
      a <code><![CDATA[<table>]]></code> tag in HTML and one
      in a language describing office furniture as well.  How do you
      use these tags unambiguously, without losing functionality?
    </para>

    <para id="namesp1.5">
      The solution is to use an extension to XML called
      <term>namespaces</term> (See the W3C's recommendation, <link src="http://www.w3.org/TR/REC-xml-names/">Namespaces in
      XML</link>).  A namespace associates a unique global identifier
      (usually a URI) with a particular set of tags and their usage
      rules.  To declare a namespace for a particular tag, set the
      <code>xmlns</code> attribute to the value of the unique
      identifier. 
    </para>

    <para id="namesp2">
      You can also define a <term>namespace prefix</term> for use in
      your document.  To do this, use a modified version of the
      <code>xmlns</code> attribute.  For example, you would
      use the attribute
      <code>xmlns:foo="http://somewhere.org/foo"</code> to
      associate the prefix <code>foo</code> with the namespace
      identifier <code>http://somewhere.org/foo</code>.  You
      can then indicate which tags come from that namespace by adding
      the appropriate prefix to each tag.  Thus, the
      <code>bar</code> tag in foo's namespace would be written
      as <code>&lt;foo:bar&gt;</code> and
      <code>&lt;/foo:bar&gt;</code>.
    </para>
<para id="namesp3">
      When you use the default namespace  any children of that tag
      lacking an explicit prefix will be assumed to have come from the
      same namespace.  This allows you to define a default namespace
      for all of the children of a tag.  This is especially useful
      when used on the <term>root node</term>, which is the outermost
      tag in a document.
</para>
    <example id="namesp">
      <para id="namesp4">
	The namespace identifier for version 0.5 of CNXML is
	<code>http://cnx.rice.edu/cnxml</code>. Thus to
	declare CNXML as the default namespace for a document, you would
	add the attribute
	<code/> to the
	<code>document</code> tag.  Similarly, the namespace
	identifier for MathML is
	<code>http://www.w3.org/1998/Math/MathML</code>, so to
	associate the MathML namespace with the prefix
	<code>m</code>, add the attribute
	<code>xmlns:m="http://www.w3.org/1998/Math/MathML"</code> 
	to the <code>document</code> tag.
      </para>
    </example>
   <para id="p1">
      Namespaces allow you to write documents in multiple languages at
      the same time.
      However, in order for these documents to be valid, they must
      have a <term>Document Type Definition</term> (DTD) that allows
      tags from one language to exist inside tags from another
      language.  So if you want to include MathML in a CNXML
      document, you would need a DTD that allowed MathML to exist
      inside certain CNXML tags. Once that DTD existed, you would
      declare the DOCTYPE the same as normal.  
    </para>
    <example id="cmcombo">
      <para id="pcnxp"> For just CNXML, the doctype declaration is:
      </para>
      <code type="block">
    <![CDATA[<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5//EN" 
              "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_plain.dtd">]]>
      </code>
      <para id="pcnxmath"> For CNXML and MathML, the doctype declaration is:
      </para>
      <code type="block">
    <![CDATA[<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" 
              "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">]]>
      </code>
      <para id="pcnxqml"> For CNXML and QML, the doctype declaration is:
      </para>
      <code type="block">
    <![CDATA[<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus QML//EN" 
              "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_qml.dtd">]]>
      </code>
      <para id="pcnxqmlmath"> For CNXML, QML, and MathML, the doctype declaration is:
      </para>
      <code type="block">
    <![CDATA[<!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">]]>
      </code>
    </example>
    <para id="p2">
      Here is a simple document with both CNXML and MathML.  Notice
      that the CNXML namespace is the default and the MathML namespace
      has the <code>m</code> prefix.
    </para>
<code type="block"><![CDATA[<?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>2001/06/29</md:created>
  <md:revised>2004-04-19T19:09:52Z</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:authorlist>

  <md:maintainerlist>
    <md:maintainer id="mizar">
      <md:firstname>Christine</md:firstname>
      
      <md:surname>Donica</md:surname>
      <md:email>mizar@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="selc">
      <md:firstname>Sarah</md:firstname>
      
      <md:surname>Coppin</md:surname>
      <md:email>coppin@alumni.rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="jenn">
      <md:firstname>Jenn</md:firstname>
      <md:othername>A.</md:othername>
      <md:surname>Drummond</md:surname>
      <md:email>jenn@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer 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:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>XML</md:keyword>
    <md:keyword>namespace</md:keyword>
    <md:keyword>DTD</md:keyword>
    <md:keyword>tutorial</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>]]></code>
    
    <para id="last">
      So, by combining the use of namespaces and carefully written DTD's,
      you can write documents that use multiple XML languages at the same time.
    </para>

  </content>
</document>
