|
Export
標準のExport関数を使ってMathematica からXMLデータがエキスポートできます.
Export[file, expr]
Export[file, expr, format]
この関数の第1引数は,データのエキスポート先のファイル名を指定するものです.第2引数はエキスポートするデータを指定するもので,XMLデータのエキスポートの際は,これはSymbolicXML式やその他のMathematica 式になります.オプションの第3引数を出力形式の指定に使うこともできます.XMLデータのエキスポートには,"XML","NotebookML","ExpressionML","MathML","SVG"のファイル形式が使えます.
エキスポート形式を"XML"とすると,すべての式はNotebookMLまたはExpressionMLとしてエキスポートされます.
In[1]:=
Out[1]=
In[2]:=
<?xml version='1.0'?>
<!DOCTYPE Expression SYSTEM 'http://www.wolfram.com/XML/notebookml1.dtd'>
<Expression xmlns:mathematica='http://www.wolfram.com/XML/'
xmlns='http://www.wolfram.com/XML/'>
<Function>
<Symbol>Power</Symbol>
<Symbol>x</Symbol>
<Number>2</Number>
</Function>
</Expression>
エキスポート形式に"MathML"を指定すると,同様の式がMathMLとして書き出されます.
In[3]:=
Out[3]=
In[4]:=
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<semantics>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<annotation-xml encoding='MathML-Content'>
<apply>
<power/>
<ci>x</ci>
<cn type='integer'>2</cn>
</apply>
</annotation-xml>
</semantics>
</math>
Exportに渡す引数が2つだけである場合,Mathematica はファイル名の拡張子に基づいてエキスポート形式を決定します.拡張子.xmlはXMLに関連付けられています.従って,以下の例のように,Export[filename.xml, expr]はExport[filename.xml, expr, "XML"]と同じ動作をします.
In[5]:=
Out[5]=
In[6]:=
<?xml version='1.0'?>
<!DOCTYPE Expression SYSTEM 'http://www.wolfram.com/XML/notebookml1.dtd'>
<Expression xmlns:mathematica='http://www.wolfram.com/XML/'
xmlns='http://www.wolfram.com/XML/'>
<Function>
<Symbol>Power</Symbol>
<Symbol>x</Symbol>
<Number>2</Number>
</Function>
</Expression>
拡張子.mmlはMathMLに関連付けられています.従って,以下の例のように,Export[filename.mml, expr]はExport[filename.mml, expr, "MathML"]と同じ動作をします.
In[7]:=
Out[7]=
In[8]:=
<math xmlns='http://www.w3.org/1998/Math/MathML'>
<semantics>
<msup>
<mi>x</mi>
<mn>2</mn>
</msup>
<annotation-xml encoding='MathML-Content'>
<apply>
<power/>
<ci>x</ci>
<cn type='integer'>2</cn>
</apply>
</annotation-xml>
</semantics>
</math>
Export関数のConversionOptions機能を使うと,エキスポート処理に関するさまざまな詳細がコントロールできます.詳しくはXMLエキスポート変換オプションをご覧ください.
次のコマンドはこのセクションのコマンドを評価して作られたテストファイル「test.xml」および「test.mml」を削除します.
In[9]:=
|