格 千格 KiloCell

XML Format Full Guide: beautification, compression and competition

Update 2026-08-09 About 13 minutes development tools How-to

Retrieve a row of crowded messages from the SOAP interface, and the Android strings.xml has been distorting the hierarchy, or the Maven/Spring configuration "looks like a similar but the solver is wrong" is often the first thing to do is not change the business field, but rather change XML A tree structure that is distributed in a uniform indentation, check if the label is paired and the entity is correct. This guide addresses the areas of beauty and compression, convergence and legitimacy, physical and naming space, and directs to the KiloCell of local XML tools.

Use tools immediately XML Formatting - Browser Insize, Compress and Indent Options
Open tool →

The core sentence.

(a) Ensure that the combination is done (well-formed) before the business fields are discussed; The beautification allows the hierarchy to be visible, and compression is left to transport and to the library.

XML is more "fat" than HTML: labels must be properly embedded and closed, attribute values must be quoted, nudised &、< It's a direct failure of the resolution. Thousands of. XML Format The glossing and compression in the browser is done manually by selecting 2 spaces, 4 spaces or Tab, and the data is not available. It helps you to see the structure, but it is not a complete XSD/DTD mode verifyr - "compatible" and "compatible with a Schema legal" are two layers, which will be discussed below.

1. What to do with each of them?

Beautify(Pretty-print / Beautify)

Change the label to a nested layer and indent it to allow a readable parent-child relationship. Typical uses:

  • SoAP/REST newspaper that reads the entire line of the log together
  • Aligning the Code Review profile
  • Check "Fixed Tags" or "Cross-Backs"

BeautifyIn principle, no semantics.: it adjusts the blanks between labels;Text Node InternalWhether meaningful spaces are touched depends on the actual realization. This station tool will be first. >…< The blanks between them are tightened and rewritten by indentation rules, suitable for the "structured text"-based message and configuration; If you rely on the exact blanks in the hybrid content (unique), you should check them in a dedicated editor.

Minify(Minify)

Removes the redundant blanks and row breaks between labels, reduces size, and allows single-line pasting to the requesting body or message queue. The compression should also not change the label name, attribute and text content itself. Note: if a paragraph of text nodeOn purpose.Include a lacuna at the end, and radical compression may affect the presentation; The configuration and API report generally do not have this problem.

Validation: a combination of the two types of data used in the data

Level What's the question? Who's to judge? Examples of failures
All-formed Satisfactory to XML Basic Syntax: Any XML Parser Labels are not closed, cross-set, nudity &
Legal (valid) Matching DTD/XSD/RelaxNG etc. Verifyer with Schema Missing required elements, type mismatch, namespace error

The daily connection, 80% of the "XML is broken" is actually...The question of convergence。 Formatting tools spread structures out through indentation, which quickly expose unclosed and cross-sets; XSD rules of operation need to be used to replace IDE,xmllint or service end check. This tool may prompt a check of syntax if you enter a visible anomaly on the formatting path, but do not consider it to be complete Schema verification.

XML border with JSON/ HTML

Points XML JSON HTML
Main uses Enterprise integration, configuration, document type data Web API, Front End State Page Structure
Comment <!-- --> None (standard) <!-- -->
Properties Elements have properties No Properties, Object Fields All has Properties
Wrong. The decrypt is almost uncorrectable. Strict Browser height is wrong
Namespace First class citizens None Limited

When you get a clip like a label and a page:Data exchange/configuration, fixed by XML-style rules; If the target isBrowser renderIt's more appropriate. HTML Format。 If the interface is moved to JSON, the interface is wrong. JSON Format。

XML rules that must be carved into muscle memory

Single root element

A single combination XML can only have one root. The following are illegal:

<item>a</item>
<item>b</item>

Should be wrapped under one root, for example. <items>…</items>, or use multiple documents/outside envelopes (SOP's Envelope is this role).

Right-set. No crosses.

<!-- Legal -->
<a><b>text</b></a>

<!-- Illegal:Hand it over.叉嵌套 -->
<a><b>text</a></b>

If you have a "symmetrical" or a "level" retreat, you have to suspect a cross-sectional closure.

Empty elements and self-conclusion

<tag></tag> and <tag/> In most scenarios, the price is equal (allowance to be subject to DTD/XSD). The team should be consistent in style and avoid mixing the same file to cause diff noise.

Properties must be quoted

<!-- Legal -->
<item id="1" name='widget'/>

<!-- Illegal:None引No, no, no. -->
<item id=1/>

If the quotation marks contain the same quotation marks, another quotation sign or the entity (or entities) shall be replaced by a quotation sign.&quot; / &apos;)。

Five predefined entities (most common rollovers)

Character Entities When must it be?
& &amp; Summation in text or attribute
< &lt; In text it is less than a mark
> &gt; Suggested transposition, part of the location can be written naked
" &quot; Double quote attribute values inside
' &apos; Single quote attribute values inside

Classic accident: URL query string a=1&b=2 Plug in the element text as it is. The solver is in &b The government has not yet made a decision on the issue. It's written correctly. a=1&amp;b=2, or put the whole section in CDATA(See below).

CDATA: When to use, when to use

<scriptDesc><![CDATA[
  if (a < b && c > d) { ... }
]]></scriptDesc>

CDATA Keep character almost as it is (except not visible) ]]> Sequence) suitable for embedded code segments or already contained in large quantities < & .don't wantAvoiding otherwise structured fields with CDATA; Security-sensitive content remains filtered in accordance with operational rules.

Declaration, Encoding and BOM

Common declaration:

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

The declaration must be in the file ' s best position (the lead blank is not welcome in part of the solver). If the code declaration is inconsistent with the true byte code, the Chinese text is either miscoded or directly deciphered. Windows notes save as UTF-8 with BOM, which occasionally leads to a "first line is not a declaration" type error - a check with hexadecimal or editor "Shows invisible characters".

Name space is not decoration.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <m:GetPrice xmlns:m="urn:example">
      <m:Item>Book</m:Item>
    </m:GetPrice>
  </soap:Body>
</soap:Envelope>

Prefixes must be bound to URI; It's missing when copying paste. xmlns:, or confuses the default naming space with the prefix of the sub-element, often in the form of "local tests that pass and report unknown elements". Formatting will help you see the level, but...No automatic naming space。

3. Thousands of cells for gradual operation

tools page:XML Formatting and Compressing。 The interface is a double bar to the left (or above):Input XML / OutputResult, in between the operation and indent settings.

3.1. Beautification of a crowded paper

  1. Opens the toolbar to confirm the theme comfort (the top right can be toggle light/dark).
  2. Paste original text in "Input XML" Or a little. Load examples First familiar with output form (example is tape) note / items - The demonstration tree.
  3. Yes. Indent Lower Larry chooses:
  • 2 spacesFront-end/part open-source project habits
  • 4 spaces(Default): Many Java/Enterprise Configuration and IDE Defaults
  • Tab: Usage only when the warehouse explicitly requests Tab
  1. Click Format (Beautify)。
  2. The results of the inspection are at the level of "output": Use CopyResult Postes the editor, worksheet or diff tool.

If you enter empty, the tool will prompt you to enter XML first. When dealing with anomalies, you are prompted to check the syntax - and then return to the Rule and the following error table, instead of the repeated button.

3.2 Compressed before sending

  1. Confirms that current input is alreadyFullContent (may be adorned by the eye, then glued back into the input or directly compressed with the already integrated text).
  2. Click Minify (Minify): The blanks between labels are removed and a tighter single line/string is obtained.
  3. Copy to HTTP request, message middle or scene that requires save.

The Joint Recommendations:People look at the glorified version, they upload it online.; The two-sided text should be used to avoid "A" and "B" changes.

3.3 Recommended queuing rings

Paste原始 XML
  → Format(ChooseOkay.Indent)
  → 扫One.眼Root element / Namespace / 最深One.层Yes.YesAlignment
  → IfFailedorStructure怪异:PressError表ChangeEntities、闭合、引No, no, no.
  → Again.FormatConfirm.
  → Yes.传Lose.TimeAgain.Minify
  → CopyFrontYeah.Key、Token、ID number脱Min.

3.4 Local processing of borders (incorporated in custom)

  • Logical is done in the browser.No pass-over server; Do not stick unsensitized production keys around as test data.
  • This tool focuses onIndentation beautification and space compression, not XSD, not XML digital signature tool, nor SOAP UI.
  • Large files may be restricted by browser memory and text domain performance; Logs above trillions suggest first the relevant clips or the desktop tool.
  • Formatting algorithms reset blanks by label boundary, and the error information entered for extreme malformations is less precise than the specific solver - with the "is it stabilised + the eye level" as the first objective.

4. Common errors and treatments

Symptoms / Wrong Keywords Common causes Approach
Tabs are not closed / unexpected end Lower </tag>, or cut off while (a) The parenthesis is then compared from the innermost to the outer brackets; Editor "Choose Tabs"
Cross-set / not normally set </a> and </b> It's the opposite. Promise to open up and close up.
Entity citation not defined It's naked in the text. &or in writing &foo; but not stated Replace with &amp;; Custom entity needs DTD
Properties without quotes id=1 Or copy from HTML. All of them. id="1"
Multiple Elements Two pieces of XML, but no root. Outsourcing one floor or processing by multi-document
Declaration not at the top BOM, NOTES OR BLUE IN <?xml Front Go to BOM; Declaration Top
Uncoded Declares that UTF-8 is actually a GBK etc. Save Unifiedly as UTF-8; Check the channel decoded.
Name space element "lost" Leak xmlns, or prefixed to error URI Compare WDSL/XSD with namespace
Ham < The text is blown up. Plug code/ HTML into element untransferred &lt; or CDATA
"A blank hole" after formatting. Enter a semi-set or a note/string with a false label First, we'll intercept the whole root element before processing it.
Business anomaly after compression Relying text node boundary blank Retain the blanking of the field
Android strings.xml Resource Failure Not converted ' &or placeholder destroys the label (a) Translating according to the rules of the Platform; After a Spectrum Level
SOAP Fault Fault in line Body; Compare valuecode/ valuestream
Maven pom.xml Parsing failed Tag spelling, relying on node intersections Verified check dependency Is it a match?

Principles: When formatting fails, the input is reduced to a "minimum replicable clip" (reserve root and error node), the alignment is made, and the context is restored. Don't blindly change in tens of KiloCell of lines.

5. Real work landscape

Scenario A: SOAP / Enterprise Interface Linking

Back to the end of the line Envelope, or request for local packaging was denied. Practices:

  1. Plug in to the request/response tool FormatConfirmed. Header / Body Level.
  2. Checks whether the namespace URI is consistent with the WSDL (prefixed variable, URL unaltered).
  3. Check if Body Operations Node is overpacked/underpacked.
  4. Once you've finished, if the gateway is single, then again. Minify (a) Send out; A beautified attachment to the work plan is maintained.

The scene is B: Android. strings.xml / Resources XML

Build an XML parsing error after translating or merging a branch. Practices:

  1. Beautify strings.xml Or playout, see if there's any unclosed <string> / <LinearLayout>。
  2. Abbreviations, unmarks,& Convert to Android resource rules (e.g. in text) '、&)。
  3. Harmonized indent (recommendation 4 or in line with Android Studio), reducing meaningless diff.
  4. The idea of "concentrating" the signed binary resources is not to be used as a "concentrated" illusion. What's beautiful about this place?Source XML。

C:Maven pom.xml / Spring and Log Configuration

pom.xml Reliance not effective,logback.xml Not on board. Practices:

  1. And then you'll be able to confirm every one of them. dependency、appender、logger Close it in pairs.
  2. See if the note is written near the label, causing semi-stop tags.
  3. The difference is usually in the missing nodes or in the naming space.
  4. Compression Before SubmitUsually, no need.— Source library cares more about readable diff; Compression is left to interfaces.

Scene D: RSS/Atom, SVG Script, Exported Excel XML

Content team export feed or design to drop SVG. Practices:

  1. Let's go and look at the root first. rss / feed / svg Which one.
  2. SVG often contains a large number of paths and properties, and is a good way to find the wrong label, but confirm before recompression whether the viewer is sensitive to the blank (most path data are in the properties, are safer).
  3. Feed HTML content is often found in CDATA or entities; Don't break it when you change the description. ]]>。

6. Submission and sharing of pre-check lists

  • [ ] It worked. Format Once again, the level is normal.
  • [ ] There is and only one root element (or a clear multi-document strategy)
  • [ ] No cross-tips; Empty element style uniform
  • [ ] In text and attributes & < (a) Has been processed; Use CDATA where necessary
  • [ ] Declarations are coded in line with the true file code; No trouble, BOM.
  • [ ] Naming space URI corresponds to the end-to-end contract
  • [ ] De-sensitization: Token, password, ID number, Intranet address
  • [ ] Recompression when uplink is required; Repository configuration to remain readable
  • [ ] If business requirements are legitimate, run XSD/DTD, not just by beautification

8. Small habits in teamwork

  1. The contract goes first.SOAP/XML API is based on XSD/WSDL instead of on a certain package-sailing result.
  2. Unified Indentation: Fixed 2 or 4 spaces in the editor with CI to avoid Tab/Space.
  3. I'll review the saffron.: Pr configuration XML formatted and diffed, less "whole file line" cannot be reported.
  4. Example Library: prepare a minimal combination of dissensitized models, and new people run through format and fill fields.
  5. Log Policy: Production logs can be cut off from XML body; The local beauty of the entire section is taken when the barrier is in place.

FAQ

Will formatting change my business data?

Normal, beauty and compression only adjust.Between Tabs, the label name, attribute name and attribute value text is not changed. Except that your application relies on "spaces at both ends of the text node" or on precise blanks in the hybrid content -- such needs should be clearly identified at the operational level. xml:space Or change the data model rather than expect the common formatting tool to retain each of the blanks. The most stable way to confirm is to apply a side run to the snapshot after formatting.

Why is my XML working in a browser and weird in a tool?

When the browser opens a page like XML, it is possible to misdecompose by HTML, automatically fills the tab and ignores some errors. XML tools and strict solvers go by the same rules, cross-set, nudity & More sensitive. Here.End service or standard XML parseris the same as the browser rendering. If content is HTML, change to HTML formatting tool.

What about XSD verification? Is this tool enough?

This tool solves the problem ofRereadability and coming level structural exposure, does not replace XSD/DTD verification. Whether fields are filled in, whether the listing is legal or not, and whether the type is xs:date, to the IDE, the CI (e.g. xmllint --schema) or service end checking chain completed. Recommended process: Admiring and fixing the tool, then running Schema and finally connecting.

Did you break the compression to report the wrong end?

Most times not. First,Same one.The compression results are re-approved locally to see if the structure is consistent with the original; Checks whether the Enter-Type, character encoding, BOM, gateway does not allow a character. If the restoration is consistent with the original structure and the problem is still hanging at the end, the problem is more likely to be HTTP header, signature, time stamp or business field than the minify itself. If the structure changes after the restoration, the text nodes are checked with the smallest sample.

Can you format a few megagrams of XML?

You can try, but the browser text field has a ceiling on memory, and both Cardon or failure are normal. Substantive: used head/grep/ Log Platform first relevant Envelope , or the spectrosm near which the error occurred; or switch to desktop editor, flow tool. What's wrong with the banding?Minimum RecurrenceNot to be able to get the whole library out again.

Tab, which is better with the space?

The XML grammar itself is not mandatory.Teamworks.More important. Java/Android/Maven Ecologic Common 4 Spaces; Part front-end warehouse is 2 spaces; Tab is easily miscalculated at different editor widths. This tool is supported by all three, select and store .editorconfig One of the same. Do not mix with the same file.

Continue reading

After using the term "co-opt and then change business and compress where necessary" as a fixed technique, the XML network moved from a subject of genre to a list.