<?xml version="1.0" encoding="utf-8"?>
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:bib="http://bibtexml.sf.net/" xmlns:q="http://cnx.rice.edu/qml/1.0" id="m10159" module-id="" cnxml-version="0.6">
  
  <title>Combining XML Languages</title>

  <metadata xmlns:md="http://cnx.rice.edu/mdml/0.4">
  <!-- WARNING! The 'metadata' section is read only. Do not edit below.
       Changes to the metadata section in the source will not be saved. -->
  <md:content-id>m10159</md:content-id>
  <md:title>Combining XML Languages</md:title>
  <md:version>2.16</md:version>
  <md:created>2001/06/29</md:created>
  <md:revised>2009/02/03 11:37:10.206 US/Central</md:revised>
  <md:authorlist>
    <md:author id="selc">
        <md:firstname>Sarah</md:firstname>
        <md:surname>Coppin</md:surname>
        <md:fullname>Sarah Coppin</md:fullname>
        <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:fullname>Brent Hendricks</md:fullname>
        <md:email>brentmh@rice.edu</md:email>
    </md:author>
    <md:author id="cnxorg">
        <md:firstname/>
        <md:surname>Connexions</md:surname>
        <md:fullname>Connexions</md:fullname>
        <md:email>cnx@cnx.org</md:email>
    </md:author>
  </md:authorlist>
  <md:maintainerlist>
    <md:maintainer id="selc">
        <md:firstname>Sarah</md:firstname>
        <md:surname>Coppin</md:surname>
        <md:fullname>Sarah Coppin</md:fullname>
        <md:email>coppin@alumni.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:fullname>Brent Hendricks</md:fullname>
        <md:email>brentmh@rice.edu</md:email>
    </md:maintainer>
    <md:maintainer id="cnxorg">
        <md:firstname/>
        <md:surname>Connexions</md:surname>
        <md:fullname>Connexions</md:fullname>
        <md:email>cnx@cnx.org</md:email>
    </md:maintainer>
    <md:maintainer id="mizar">
        <md:firstname>Christine</md:firstname>
        <md:surname>Donica</md:surname>
        <md:fullname>Christine Donica</md:fullname>
        <md:email>mizar@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:fullname>Jenn Drummond</md:fullname>
        <md:email>jenn@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  <md:license href="http://creativecommons.org/licenses/by/1.0"/>
  <md:licensorlist>
    <md:licensor id="selc">
        <md:firstname>Sarah</md:firstname>
        <md:surname>Coppin</md:surname>
        <md:fullname>Sarah Coppin</md:fullname>
        <md:email>coppin@alumni.rice.edu</md:email>
    </md:licensor>
    <md:licensor id="brentmh">
        <md:firstname>Brent</md:firstname>
        <md:othername>Michael</md:othername>
        <md:surname>Hendricks</md:surname>
        <md:fullname>Brent Hendricks</md:fullname>
        <md:email>brentmh@rice.edu</md:email>
    </md:licensor>
  </md:licensorlist>
  <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:subjectlist>
    <md:subject>Science and Technology</md:subject>
  </md:subjectlist>
  <md:abstract>This module explains how to use XML namespaces and DTDs to combine multiple XML languages in the same document.</md:abstract>
  <md:language>en</md:language>
  <!-- WARNING! The 'metadata' section is read only. Do not edit above.
       Changes to the metadata section in the source will not be saved. -->
</metadata>

<content>
    <para id="namesp1">
      <link url="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>&lt;table&gt;</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 url="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="cmcombo"><para id="pcnxp"> For CNXML 0.6 there is only one schema. The document tag will contain the namespace for all available languages and will look like this:
      </para>
      <code id="id1332779" display="block">
    &lt;document xmlns="http://cnx.rice.edu/cnxml"
              xmlns:md="http://cnx.rice.edu/mdml/0.4"
              xmlns:bib="http://bibtexml.sf.net/"
              xmlns:m="http://www.w3.org/1998/Math/MathML"
              xmlns:q="http://cnx.rice.edu/qml/1.0"
              id="new"
              cnxml-version="0.6"
              module-id="new"&gt;
      </code>
    </example>
    

    
    

  </content>
</document>
