<code>
Code (コード)
プログラミング言語コード、疑似コード、スキーマ、マークアップフラグメントなどの技術的な内容のコンテナ要素。
備考
<code> 要素には書式設定済みのテキストが含まれている可能性があります。これにはシンタックス・カラーリングの強調要素が含まれている場合もあれば、バイナリ実行可能ファイルへの外部リンクが含まれている場合もあります。
最適な属性の用法: コード、言語、意図されたプラットフォームなどの種類を示すために、さまざまな意味属性を使用する必要があります。実行可能コードは @executable 属性を使用して常にマークする必要があります。@specific-use 属性は、コードサンプルの根拠や用途を記述するためにも使用できます。
代替法: コードが複数の形式で存在する場合、<code> 要素は <alternatives> 要素内で使用できます。コードの様々な版は、このタグセットからのマークアップを使用してシンタックス・カラーリングができます。これには、シンタックス・カラーリングプログラムから処理命令または他の機構を使用するもの、あるいは単純 ASCII のカット・アンド・ペースト、実行可能版などがあります。
MathML: 方程式を記述するMathML要素は <code> 内では許されません。方程式がコンピュータコード内に存在した場合は、方程式であるという事実を保存するために <named-content> 要素を使用し、また数学フォントで設定されたという事実を保存するために <styled-content> 要素でタグ付けできます。
属性
拡張コンテンツ・モデル
(#PCDATA | email | ext-link | uri | bold | fixed-case | italic | monospace | overline | roman | sans-serif | sc | strike | underline | ruby | abbrev | milestone-end | milestone-start | named-content | styled-content | fn | target | xref | sub | sup)*
この要素は以下の要素内に含むことができます:
<alternatives>, <app>, <app-group>, <bio>, <body>, <boxed-text>, <chem-struct>, <chem-struct-wrap>, <disp-formula>, <disp-quote>, <fig>, <floats-group>, <glossary>, <license-p>, <named-content>, <notes>, <p>, <ref-list>, <sec>, <styled-content>, <supplementary-material>, <table-wrap>, <td>, <term>, <th>
用例 1
XML 文書の部分:
...
<p>An example XML WorkOrder element is shown as follows:
<code 
   code-type="xml" 
   language-version="1.1"
   xml:space="preserve" 
   orientation="portrait"
   position="anchor" >
…
<WorkOrder ID=”P7710”>
  <WorkItem name=”Testing”>
    <Datum xsi:type=”string” value=”A123”/>
  </WorkItem>
</WorkOrder>
…
</code>
</p>
...用例 2
XSD Schema の部分:
...
<p>As of the release of this standard, the schema described 
incorporates the following “header” information:
<code 
  code-type="xml"
  language="xsd"
  language-version="1.1" 
  xml:space="preserve" 
  orientation="portrait"
  position="anchor" >
<xs:schema 
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:c="urn:IEEE-1671:2008.01:Common"
    xmlns="urn:IEEE-1636.1:2008.01:TestResults"
    targetNamespace="urn:IEEE-1636.1:2008.01:TestResults"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    version="2.01">
  <xs:import namespace="urn:IEEE-1671:2008.01:Common"
    schemaLocation="Common.xsd"/>
</xs:schema>
</code>
</p>
...用例 3
DTD の部分:
<article dtd-version="1.1">
<front>...</front>
<body>...
<p>Trees, of course, are hardly a random choice for our
methodology. ... Hierarchical trees have been understood as a
way of viewing document structures since the earliest days of
SGML development. Our initial tree structure was very simple:
<code code-type="dtd">
<!ELEMENT  implications  (tree+) >
<!ELEMENT  tree          (root, branches) >
<!ELEMENT  root          (term, synonym?) >
<!ELEMENT  branches      (term | (term, synonym) | tree)* >
</code>
Terms are the literal strings for which the Ferret engine searches; they
are the most specific expressions to be found in real documents of the
concepts on which classifications rules act.</p>
...</body>
<back>...</back>
</article>
用例 4
XSLT スタイルシートの部分:
...
<p>As you can see in the following excerpt, use of literal
result elements is very convenient:
<code code-type="xml" language="xslt">
<xsl:template match="div/divhead" priority="2">
  <<bold>h2</bold>>
    <xsl:apply-templates/>
  <<bold>/h2</bold>>
</xsl:template>
</code>
</p>
...