DevToolBox

XML Formatter & Validator

XMLの整形・検証をブラウザ上で行います。パースエラーを明確に表示。

How to Use the XML Formatter & Validator

This free online XML tool formats and validates your XML data in one step. Paste your XML into the input area, choose your preferred indentation, and click "Format & Validate". The tool will check for well-formedness and display either the formatted output or clear error messages.

Features

  • XML validation using the browser's built-in DOMParser
  • Pretty-printing with customizable indentation (2 or 4 spaces)
  • Clear error messages for malformed XML
  • Self-closing tag detection for empty elements
  • Attribute preservation and proper formatting

What Makes Valid XML?

Valid (well-formed) XML requires all tags to be properly closed, attributes to be quoted, elements to be properly nested, and a single root element. Unlike HTML, XML is strict about syntax. A missing closing tag or unescaped ampersand will cause a parse error. This tool uses the browser's native XML parser to detect all such errors.

Common XML Errors

The most common XML errors include unclosed tags, mismatched tag names, unescaped special characters (use &amp; for &, &lt; for <, &gt; for >), missing quotes around attribute values, and multiple root elements. This validator will identify these issues and help you fix them quickly.

Well-formed vs. Valid: What This Tool Checks

Strictly speaking, "well-formed" means the document obeys XML syntax rules, while "valid" means it also conforms to a schema (XSD or DTD). This tool performs well-formedness checking, which catches the vast majority of everyday XML problems. If you also need schema validation, fix the syntax here first, then run a schema-aware tool such as xmllint --schema — a document that is not well-formed can never pass schema validation anyway.

XMLフォーマッター & バリデーターの使い方

XMLデータをテキストエリアに貼り付け、インデント幅を選択して「整形 & 検証」ボタンを押すと、 整形されたXMLが出力されます。パースエラーがある場合は明確なエラーメッセージが表示されるため、 問題箇所をすばやく特定・修正できます。全ての処理はブラウザ内で完結し、データは外部に送信されません。

本ツールが行うのは「well-formed(整形式)チェック」です。タグの対応、属性の引用符、入れ子構造、 ルート要素の一意性など、XML構文上の誤りをすべて検出します。XSDやDTDに対するスキーマ検証は 行いませんが、構文エラーが残ったままではスキーマ検証も通らないため、まず本ツールで構文を 直すのが最短ルートです。

実務での活用例

1. SOAP/レガシーAPIレスポンスのデバッグ

SOAPベースのWebサービスや基幹システム連携では、レスポンスが改行なしの1行XMLで返ってくることが よくあります。そのまま目視するのは困難ですが、本ツールで整形すれば Envelope → Body → Fault の 階層が一目で追えます。Fault要素内のエラーコードを探す、名前空間接頭辞の対応を確認する、といった 調査が格段に速くなります。

2. 設定ファイル(pom.xml / web.config / AndroidManifest.xml)の整形とレビュー

MavenのpomやIIS/.NETのweb.config、AndroidのManifestなど、XMLベースの設定ファイルは手編集で インデントが崩れがちです。コミット前に整形しておくとレビュー差分が実質的な変更だけになり、 タグの閉じ忘れもプッシュ前に検出できます。CI が「ビルドファイルが壊れている」と落ちる前の ローカル検証としても有効です。

3. RSS/サイトマップの検証とJSON変換

Search Console で「サイトマップを読み込めませんでした」と出る原因の多くは well-formed でない XMLです。sitemap.xml や RSS フィードを貼り付ければ、URL中の未エスケープの & や 閉じタグ漏れをすぐ特定できます。検証後のXMLをプログラムでJSONとして扱いたい場合はXML to JSON でそのまま変換できます。

よくあるエラーと対処 / Common Errors and Fixes

ブラウザのXMLパーサー(libxml2系)が報告する代表的なエラーと修正方法です。メッセージの文言は ブラウザにより多少異なります。

Typical errors reported by browser XML parsers (libxml2-based) and how to fix them. Exact wording varies by browser.

エラー / Error原因 / Cause対処 / Fix
Opening and ending tag mismatchタグの閉じ忘れ・タグ名の不一致
Unclosed tag or mismatched tag name
対応する閉じタグを補う。XMLは大文字小文字を区別し <Item></item> は別タグ
Add the matching closing tag; XML is case-sensitive, so <Item></item>
AttValue: " or ' expected属性値が引用符で囲まれていない
Attribute value is not quoted
id=1id="1" に。HTMLと違い引用符は省略不可
Quote every attribute value; unlike HTML, quotes are mandatory
xmlParseEntityRef: no nameテキストや属性中の生の &(URLのクエリ等に多い)
Raw ampersand in text or attributes (common in URLs)
&amp; にエスケープするか CDATA で囲む
Escape as &amp; or wrap the text in CDATA
Namespace prefix xxx is not definedxsi:type 等の接頭辞が未宣言
Namespace prefix used without declaration
ルート要素に xmlns:xsi="..." を追加。部分コピーで宣言が欠けることが多い
Declare it on the root element; partial copies often drop the declaration
Entity 'nbsp' not definedHTML用の実体参照はXMLに存在しない
HTML entities are not predefined in XML
XML定義済み実体は5つのみ(&amp; &lt; &gt; &quot; &apos;)。&#160; など数値文字参照を使う
Only 5 entities are predefined; use numeric references like &#160;
CData section not finished]]> の閉じ忘れ、またはCDATA内に ]]> を含む
CDATA section not closed, or it contains a literal ]]>
末尾に ]]> を補う。内包する場合はCDATAを2つに分割
Add the closing ]]>; split the CDATA in two if it must contain one
Extra content at the end of the documentルート要素が複数ある
More than one root element
全体を1つのルート要素で包む。ログ連結XMLに多い
Wrap everything in a single root; common with concatenated log fragments
XML declaration allowed only at the start of the document<?xml ... ?> の前に空白・BOM・コメントがある
Whitespace, BOM, or comments before the XML declaration
宣言を1文字目から始める。エディタでBOMなしUTF-8で保存し直す
Make the declaration the very first bytes; re-save as UTF-8 without BOM

言語別コード例 / Code Examples by Language

XMLの整形・検証をアプリ側で再現するための最小サンプルです。

Minimal snippets to format and validate XML programmatically.

JavaScript (Browser)

// 検証 / Validate (本ツールと同方式 / same approach as this tool)
const doc = new DOMParser().parseFromString(xml, "application/xml");
const err = doc.querySelector("parsererror");
if (err) {
  console.error(err.textContent); // パースエラー詳細 / parse error details
}

// 再シリアライズ / Re-serialize (整形はノード走査で行う)
const out = new XMLSerializer().serializeToString(doc);

Python

import xml.dom.minidom as minidom
from xml.parsers.expat import ExpatError

try:
    # 整形 / Pretty-print (2-space indent)
    pretty = minidom.parseString(s).toprettyxml(indent="  ")
except ExpatError as e:
    # 行・列付きで構文エラーを取得 / syntax error with line/column
    print(f"line {e.lineno}, col {e.offset}: {e}")

Go

import (
    "bytes"
    "encoding/xml"
    "io"
)

func formatXML(src []byte) (string, error) {
    d := xml.NewDecoder(bytes.NewReader(src))
    var buf bytes.Buffer
    e := xml.NewEncoder(&buf)
    e.Indent("", "  ") // 整形 / pretty-print
    for {
        tok, err := d.Token()
        if err == io.EOF {
            break
        }
        if err != nil {
            return "", err // 構文エラー / syntax error
        }
        e.EncodeToken(tok)
    }
    e.Flush()
    return buf.String(), nil
}

Shell (xmllint)

# 整形 / Pretty-print
xmllint --format input.xml

# 検証のみ / Well-formedness check only
xmllint --noout input.xml

# XSDスキーマ検証 / Validate against an XSD schema
xmllint --noout --schema schema.xsd input.xml

Before / After 実例 / Before & After

例1: 1行のAPIレスポンスを可読化 / Pretty-print a single-line response

<?xml version="1.0" encoding="UTF-8"?><order id="1001"><customer>Yamada</customer><total currency="JPY">5400</total></order>

<?xml version="1.0" encoding="UTF-8"?>
<order id="1001">
  <customer>Yamada</customer>
  <total currency="JPY">5400</total>
</order>

例2: 空要素を自己終了タグに統一 / Collapse empty elements

<config>
  <cache></cache>
  <debug enabled="false"></debug>
</config>

<config>
  <cache />
  <debug enabled="false" />
</config>

子を持たない要素は <tag /> 形式に揃えられ、差分レビューのノイズが減ります。

Childless elements are normalized to the <tag /> form, reducing diff noise.

例3: 未エスケープの & を修正 / Fix a raw ampersand

<company>Johnson & Johnson</company>  ← xmlParseEntityRef: no name

<company>Johnson &amp; Johnson</company>

テキスト中の & は必ず &amp; へ。URLのクエリ文字列(?a=1&b=2)が混入源の定番です。

Every literal & must become &amp;; URL query strings are the usual culprit.

Why browser-only? / なぜブラウザ完結か

XML is rarely just markup. The documents developers paste into formatters are oftenweb.config files containing database connection strings, pom.xmlfiles referencing private repository credentials, SOAP responses carrying customer records, or e-invoicing and EDI payloads with bank details. Sending any of these to a server-hosted "free formatter" hands the content to a third party — even if only a formatted string comes back, your data has already left your machine and may sit in someone's access logs. This tool formats and validates XML entirely inside your browser using the native DOMParser API. There is no upload endpoint and no processing server. You can verify this yourself: open DevTools, switch to the Network tab, format a document, and watch — no request fires. Once the page has loaded, the tool even keeps working offline.

XMLは単なるマークアップではなく、web.config のDB接続文字列、SOAPレスポンス内の顧客情報、 電子インボイスの口座情報など、機密データを含むことが多い形式です。サーバ送信型の整形ツールでは 中身が第三者に渡り、アクセスログに残る可能性もあります。本ツールはブラウザ内蔵の DOMParser のみで 整形・検証を行い、通信は一切発生しません。DevTools の Network タブが空のままであることで確認でき、 読み込み後はオフラインでも動作します。

開発をもっと効率的に

PR