サンプル
./data/lesson/ に置いたXMLをそのまま読めるようにしています。
books(属性+要素)
data/lesson/sample_books.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id="bk001" lang="ja">
<title>XMLの基本</title>
<author>SunStripe</author>
<price currency="JPY">980</price>
<tags>
<tag>初心者</tag>
<tag>構造</tag>
<tag>データ交換</tag>
</tags>
</book>
<book id="bk002" lang="en">
<title>XML & Namespaces</title>
<author>ProLab</author>
<price currency="USD">9.99</price>
<tags>
<tag>namespace</tag>
<tag>schema</tag>
</tags>
</book>
</books>
person(入れ子+配列)
data/lesson/sample_person.xml
<?xml version="1.0" encoding="UTF-8"?>
<person>
<name>
<first>Rina</first>
<last>Harukaze</last>
</name>
<contacts>
<email primary="true">rina@example.com</email>
<social service="X">https://x.com/example</social>
</contacts>
<skills>
<skill level="3">PHP</skill>
<skill level="4">JavaScript</skill>
<skill level="2">XML</skill>
</skills>
</person>
rss(名前空間っぽい雰囲気)
data/lesson/sample_rss.xml
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>SunStripe Updates</title>
<link>https://sunstripe.main.jp/</link>
<description>XML/RSSのサンプルです。</description>
<item>
<title>XMLページを追加</title>
<link>https://sunstripe.main.jp/programming/xml/</link>
<guid>sunstripe-xml-001</guid>
<pubDate>Sat, 07 Feb 2026 13:00:00 GMT</pubDate>
</item>
<item>
<title>エクスポート/インポート体験を実装</title>
<link>https://sunstripe.main.jp/programming/xml/?tab=import</link>
<guid>sunstripe-xml-002</guid>
<pubDate>Sat, 07 Feb 2026 13:30:00 GMT</pubDate>
</item>
</channel>
</rss>
ブラウザ側の簡易バリデーション
下のテキストにXMLを貼り、JS(DOMParser)で「整形式か」をチェックできます。
待機中