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 & for &, < for <, > 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=1 を id="1" に。HTMLと違い引用符は省略不可Quote every attribute value; unlike HTML, quotes are mandatory |
xmlParseEntityRef: no name | テキストや属性中の生の &(URLのクエリ等に多い)Raw ampersand in text or attributes (common in URLs) | & にエスケープするか CDATA で囲むEscape as & or wrap the text in CDATA |
Namespace prefix xxx is not defined | xsi:type 等の接頭辞が未宣言Namespace prefix used without declaration | ルート要素に xmlns:xsi="..." を追加。部分コピーで宣言が欠けることが多いDeclare it on the root element; partial copies often drop the declaration |
Entity 'nbsp' not defined | HTML用の実体参照はXMLに存在しない HTML entities are not predefined in XML | XML定義済み実体は5つのみ(& < > " ')。  など数値文字参照を使うOnly 5 entities are predefined; use numeric references like   |
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.xmlBefore / 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 & Johnson</company>テキスト中の & は必ず & へ。URLのクエリ文字列(?a=1&b=2)が混入源の定番です。
Every literal & must become &; 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 タブが空のままであることで確認でき、 読み込み後はオフラインでも動作します。
関連ツール / Related Tools
開発をもっと効率的に
PR
レンタルサーバー
エックスサーバー
国内シェアNo.1の高速レンタルサーバー(エックスサーバー社調べ)。WordPressも簡単セットアップ。
詳しく見る →レンタルサーバー
ConoHa WING
国内最速クラスのレンタルサーバー。独自ドメイン永久無料特典付き(特典内容は変更される場合があります)。
詳しく見る →レンタルサーバー
mixhost
高速SSD・HTTP/3対応のクラウド型レンタルサーバー。
詳しく見る →VPS
シンVPS
メモリ単価国内最安・オールNVMe SSD搭載の高性能VPS。開発・検証環境の構築に。
詳しく見る →Windows VPS
ConoHa for Windows Server
Windows環境のVPS。リモートデスクトップで開発・検証環境を構築。
詳しく見る →