Developer Công cụ đã được cập nhật 4 tuần trước

XML Minifier

XML Minifier strips indentation and whitespace-only nodes from valid XML, collapsing a formatted document onto one line. Comments, CDATA, the DOCTYPE, namespaces and text content are kept as they are. Paste or load a file, minify, then copy the result or download it as minify-output.xml.

Luôn miễn phí Dễ sử dụng Kết quả ngay lập tức Riêng tư và an toàn

Sử dụng XML Minifier

Dán URL trực tiếp của tệp mã để tải nội dung của tệp đó vào trình soạn thảo.

Kết quả

Xong
Liên kết công cụ
Đã sao chép vào khay nhớ tạm.
Hãy giúp cải thiện công cụ này

Đọc nội dung

Tìm hiểu cách thức hoạt động của công cụ này và khi nào nên sử dụng nó.

What this XML minifier actually removes

Paste a formatted XML document and the tool parses it, then writes it back without the indentation. Sibling elements end up on the same line, the ASCII whitespace that only existed to make the file readable is dropped, and the result is a compact document that carries the same data.

"Minify" here has a narrow meaning. The tool removes whitespace-only nodes between elements and disables pretty printing. It does not strip comments, does not rewrite text content, does not shorten element or attribute names, and does not remove CDATA. If you need those things, this is not the tool for that job.

Before and after

Input:

<root>
  <!-- keep -->
  <a>  x   y  </a>
  <b><![CDATA[  raw  <tag>  ]]></b>
  <c attr="one two" />
  <d></d>
</root>

Output:

<?xml version="1.0"?>
<root><!-- keep --><a>  x   y  </a><b><![CDATA[  raw  <tag>  ]]></b><c attr="one two"/><d/></root>

The comment survived, the CDATA block survived, and the spaces inside the text element survived exactly as typed. Only the line breaks and indentation between elements disappeared.

What is removed and what is kept

ItemMinify behaviour
Indentation and line breaks between elementsRemoved
Whitespace-only text nodesRemoved, including spaces between inline child elements
CommentsKept
CDATA sectionsKept, contents untouched
Text content whitespaceKept exactly
DOCTYPEKept
XML declarationKept, or added if missing
Empty element pairsRewritten as self-closing tags
Attribute valuesKept, with newlines normalised to spaces per the XML spec
Namespaces and prefixesKept

The mixed-content trap

Whitespace between elements is usually insignificant, which is why removing it is safe for data documents. It becomes significant in mixed content, where text and inline elements share a parent. The parser treats an element that contains only child elements as element-only content, so whitespace-only nodes there are discarded:

<p><b>a</b> <b>b</b></p>

becomes

<p><b>a</b><b>b</b></p>

which renders as "ab" rather than "a b". If a sentence contains inline markup separated by spaces, or if you are minifying XHTML, SVG text or any document where layout depends on inter-element whitespace, check the output before publishing it. This is the one behaviour that can change meaning rather than just appearance.

What it does not do

  • It does not remove comments. A comment-heavy file stays comment-heavy.
  • It does not collapse spaces inside text. Runs of spaces in a text node are preserved.
  • It does not shorten names. No element or attribute is renamed.
  • It does not drop namespaces or unused declarations.
  • It does not validate against a schema or DTD, and it does not check that the data makes sense.
  • It does not repair invalid XML. A missing close tag or a bare ampersand fails the parse and produces no output.
  • It does not guarantee the smallest possible file. A dedicated minifier that also strips comments will usually do better.

How to use the page

  1. Make sure the language selector says XML and the mode is Minify.
  2. Paste the document into the Manual tab, or fetch a text file through the From URL tab.
  3. Press Minify. The compact document appears in the output panel, or an error appears if the input is not well-formed.
  4. Compare the output character count with the input count in the footer badges. On a typically indented file, most of the saving comes from indentation, not from content.
  5. Copy the result or download it as minify-output.xml.
  6. Run a validator or your application's parser over the result once, especially if the source had mixed content.

Where it is useful

  • Payload size. Removing indentation from a generated XML response reduces bytes, though a compression layer usually achieves more.
  • Logs and trace files. A pretty-printed request body becomes a single line that is easier to paste into a log entry or a chat message.
  • Configuration snapshots. Compact XML is easier to store in a database column or compare as one string.
  • Diff noise. When two files differ only in indentation, minifying both makes the real difference visible.
  • Embedding XML. A compact document is easier to place inside a JSON string or an environment variable.

It is a poor fit for XHTML pages, SVG artwork with text, documentation in XML, and anything that will be read by a person afterwards. Readability is the thing minification removes.

How much smaller does the output get?

The saving comes almost entirely from indentation, so it depends on how deeply the source was indented. In a test with a 20-item product catalog written with two and four space indentation, the input measured 2,344 characters and the minified output 1,946 characters, a reduction of about 17 percent. The output also gained the XML declaration, which offsets a few bytes.

A document with one tab per level and dozens of nested elements saves more. A file that was already written on a single line saves almost nothing, because only the declaration, self-closing tags and attribute normalisation change. If bytes matter enough to measure, compare the input and output counters in the footer before deciding that minification is worth the loss of readability.

What it does to already-compact XML

Running the minifier on a file that has no indentation still produces changes: the XML declaration is ensured, empty element pairs become self-closing tags, and attribute values are normalised. Comments and CDATA remain. If your input is already one line, expect the output to look nearly identical apart from those details, and expect the character count to move slightly rather than drop.

Limits

Input is capped at 200,000 characters per request. The document is parsed into memory on the server, so a deeply nested file near the limit can be slower than its size suggests. The tool handles one document per request, does not stream, does not batch files and does not preserve the original line endings because it rewrites the whole serialisation. A file with multiple root elements is invalid and is rejected.

Privacy

Your XML is sent to the server. Remove tokens, passwords, personal data and internal hostnames before pasting, particularly from SOAP envelopes, SSO assertions and configuration exports. The page does not keep a history, but the document does leave the browser during processing.

Common mistakes

  • Expecting comments to disappear. They are kept; this is not a full compressor.
  • Minifying XHTML with inline spacing. Whitespace between inline elements can be removed, changing the rendered text.
  • Minifying a signed document. Any byte change invalidates the signature.
  • Pasting HTML. Optional end tags and bare ampersands are not valid XML and fail the parse.
  • Assuming the output is airtight. Validate it once before replacing a production file.
  • Using it for archival. Keep the readable original; the compact version is for transport.

Frequently Asked Questions

Câu hỏi thường gặp

Các câu trả lời ngắn gọn cho những thắc mắc mà người dùng thường đặt ra trước khi tin tưởng vào kết quả.

No. Comments, CDATA sections, the DOCTYPE and the XML declaration are all preserved. Only indentation and whitespace-only nodes between elements are removed.

It can, in mixed content. Whitespace between inline elements inside an element that has no text of its own may be removed, so a space that separated two words can disappear.

Yes. Parsing and serialisation run on the server, so the document is sent with the request. Strip secrets first.

The tool has to parse the document before it can write it. If parsing fails, there is nothing to serialise, so the request returns an error instead of a partial result.

No. Runs of spaces in text content are preserved exactly; only whitespace-only nodes between elements are dropped.

No. Changing bytes invalidates the signature. Minify before signing, or leave signed documents untouched.

200,000 characters per request. Larger documents are rejected rather than truncated.

Bình luận (0)

Dành cho các cuộc thảo luận của người dùng, các trường hợp ngoại lệ và các mẹo bổ sung.
Để lại bình luận
Bình luận của bạn sẽ được hiển thị công khai sau khi gửi.
Chưa có bình luận nào. Hãy là người đầu tiên bình luận!
Hãy cho chúng tôi biết!
Báo cáo sự cố liên quan đến công cụ này

Hãy mô tả vấn đề mà bạn gặp phải để chúng tôi có thể tìm hiểu và cải thiện công cụ này.

Điều gì hữu ích nhất
Vui lòng cung cấp thông tin về dữ liệu đầu vào, kết quả mong đợi, kết quả thực tế, trình duyệt/thiết bị và ảnh chụp màn hình (nếu có thể).
Nút chụp màn hình sẽ chụp lại trang web trong trình duyệt và đính kèm hình ảnh được tạo ra vào biểu mẫu này.
Ảnh chụp màn hình toàn trang
Được ghi lại trên trình duyệt của bạn bằng newisty.
Chưa có ảnh chụp màn hình nào được chụp.
Công cụ Báo cáo