一般に使われている XML

みるくあいらんどっ! > ドキュメント > XML > 基礎だけ学ぶ XML講座 [初心者向け・入門]


一般に使われている XML

既に、いろいろな形で XMLが利用されています。まず、これらの例を見ていきましょう。

詳細について理解する必要はありません。全体の雰囲気を掴めば大丈夫。この節と、次の節で、いろいろな XML文書を見ることで、XML文書がどういう雰囲気のものなのか分かれば十分です。XMLがいろいろな分野で使われていることが分かり、かつ、XML文書に目慣れすることが、この節と次の節の目指すところですから。

細かいルールについては、後の章で解説します。

具体例

RSS

ニュースなどの一覧を取得するために RSSという仕組みがあります。RSSは XML文書です。以下、Yahoo! ニュースの RSSから引用しました(一部省略し、一部整形をしています)。Yahoo! ニュースの RSSはhttp://headlines.yahoo.co.jp/rss/listから取得できます。

<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0" xmlns:blogChannel="http://backend.userland.com/blogChannelModule">

<channel>
<title>Yahoo!ニュース・トピックス - トップ</title>
<link>http://dailynews.yahoo.co.jp/fc/</link>
<description>Yahoo! JAPANのニュース・トピックスで取り上げている最新の見出しを提供しています。</description>
<language>ja</language>
<pubDate>Sun, 23 Feb 2014 13:56:11 +0900</pubDate>

<item>
<title>京浜東北横転 確認ミス原因か</title>
<link>http://dailynews.yahoo.co.jp/fc/domestic/train_accindents/</link>
<pubDate>Sun, 23 Feb 2014 13:27:53 +0900</pubDate>
<enclosure length="133" url="http://i.yimg.jp/images/icon/photo.gif" type="image/gif" />

<guid isPermaLink="false">yahoo/news/topics/6118711</guid>
</item>

<item>
<title>ウクライナ大統領の出国阻止</title>
<link>http://dailynews.yahoo.co.jp/fc/world/ukraine/</link>
<pubDate>Sun, 23 Feb 2014 12:01:02 +0900</pubDate>
<enclosure length="133" url="http://i.yimg.jp/images/icon/photo.gif" type="image/gif" />

<guid isPermaLink="false">yahoo/news/topics/6118707</guid>
</item>

<!-- 省略 -->

</channel>
</rss>

SVG

SVGは、ベクター形式の画像フォーマットで XML文書のひとつです。例えば、以下の例では、青色の四角形と、赤色の円が組み合わさった画像を表現しています。なお、InternetExplorerや Firefoxは、SVGビューアーでもあるので、以下のファイルを拡張子 svgで保存すれば、実際に SVGの画像を見ることができます。

<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="640px" height="400px" version="1.1">
	<rect x="50" y="50" width="250" height="100" fill="blue" />
	<circle cx="200" cy="200" r="100" stroke-width="10" fill="red" stroke="green" />
</svg>

Firefoxで閲覧すると以下のような画像が表示されます(Firefoxの画像をキャプチャしている関係で、画像サイズは不正確です)。

SVG画像

XHTML

HTMLと同じような用途で使われる XML文書に XHTMLというものがあります。例えば、以下は、シンプルな XHTML文書です。なお、InternetExplorerや Firefoxは XHTMLビューアーでもあるので、以下のファイルを拡張子 htmlで保存すれば、実際にホームページの形式で見ることができます(文字コードは UTF-8で保存してください)。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<title>サンプル</title>
	</head>
	<body>
		<h1>サンプル</h1>
		<p>これは XHTML文書です。<em>XML文書</em>でもあります。</p>	</body>
</html>

OpenOffice.org の Writerの保存ファイル

ワープロソフトである OpenOffice.orgの Writerの保存ファイルの拡張子は odtですが、この拡張子を zipに変更すると解凍することができます。「サンプルテキスト。」とだけ記述した odtファイルの content.xmlを開くと、以下のようになっていました。規模が大きくて分かりづらいかもしれませんが、これも XML文書です。なお、見栄えを少し整えています。

<?xml version='1.0' encoding='utf-8'?>
<office:document-content
        xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
        xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
        xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
        xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
        xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
        xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
        xmlns:xlink="http://www.w3.org/1999/xlink"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
        xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
        xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
        xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
        xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
        xmlns:math="http://www.w3.org/1998/Math/MathML"
        xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
        xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
        xmlns:ooo="http://openoffice.org/2004/office"
        xmlns:ooow="http://openoffice.org/2004/writer"
        xmlns:oooc="http://openoffice.org/2004/calc"
        xmlns:dom="http://www.w3.org/2001/xml-events"
        xmlns:xforms="http://www.w3.org/2002/xforms"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:rpt="http://openoffice.org/2005/report"
        xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
        xmlns:xhtml="http://www.w3.org/1999/xhtml"
        xmlns:grddl="http://www.w3.org/2003/g/data-view#"
        xmlns:tableooo="http://openoffice.org/2009/table"
        xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
        office:version="1.2">
    <office:scripts>
        <office:font-face-decls>
            <style:font-face style:name="Tahoma1"
                    svg:font-family="Tahoma">
            </style:font-face>
            <style:font-face style:name="Times New Roman" svg:font-family="'Times New Roman'"
                    style:font-family-generic="roman" style:font-pitch="variable">
            </style:font-face>
            <style:font-face style:name="Arial" svg:font-family="Arial"
                    style:font-family-generic="swiss" style:font-pitch="variable">
            </style:font-face>
            <style:font-face style:name="Andale Sans UI" svg:font-family="'Andale Sans UI'"
                    style:font-family-generic="system" style:font-pitch="variable">
            </style:font-face>
            <style:font-face style:name="Tahoma" svg:font-family="Tahoma"
                    style:font-family-generic="system" style:font-pitch="variable">
            </style:font-face>
        </office:font-face-decls>
        <office:automatic-styles>
            <style:style style:name="P1" style:family="paragraph" style:parent-style-name="Standard">
                <style:text-properties style:language-asian="ja" style:country-asian="JP">
                </style:text-properties>
            </style:style>
        </office:automatic-styles>
        <office:body>
            <office:text>
                <text:sequence-decls>
                    <text:sequence-decl text:display-outline-level="0" text:name="Illustration">
                    </text:sequence-decl>
                    <text:sequence-decl text:display-outline-level="0" text:name="Table">
                    </text:sequence-decl>
                    <text:sequence-decl text:display-outline-level="0" text:name="Text">
                    </text:sequence-decl>
                    <text:sequence-decl text:display-outline-level="0" text:name="Drawing">
                    </text:sequence-decl>
                </text:sequence-decls>
                <text:p text:style-name="P1">
                    サンプルテキスト。
                </text:p>
            </office:text>
        </office:body>
    </office:scripts>
</office:document-content>
最終更新: 2014/03/16 , 公開: 2014/02/23
▲top