Utvikling · verktøy

XML-formaterer og -validator

Lim inn XML for å kontrollere den, og gjør den deretter enklere å lese med ett klikk.

Kjøres i nettleseren. Ingen opplasting.

XML is checked in your browser. No upload.

Om verktøyet

XML-formaterer og -validator sem complicação.

Nettleseren kontrollerer at XML er velformet og formaterer den lokalt. Dokumentet lastes ikke opp; formateringen validerer ikke et eksternt skjema eller en DTD.

Veiledning

Slik bruker du XML-formaterer og -validator

The XML Formatter and Validator checks that the XML you paste is well formed, which means the tags open and close in the right order and the quotation marks match, and then lays it out with two-space indentation. The check uses the browser's own XML parser. It does not test your file against an XSD schema or a DTD, and it refuses any document that contains a DOCTYPE.

Slik gjør du

  1. Paste your XML into the large box. The tool accepts up to 2 MB of text, which is 2,097,152 characters.
  2. Press Format XML to check the text and fill the output box with the indented version. Press Check XML if you only want the well-formed test and no output.
  3. Read the status line under the box. It says the XML is well formed, or it gives a short reason, such as a DOCTYPE being refused or the tags not matching.
  4. Press Copy XML to take the formatted text, or Clear to empty both boxes. Editing the input also clears the output.

Eksempler

Indenting one long line

Du skriver inn
XML
<?xml version="1.0"?><library><book id="1"><title>Dune</title><year>1965</year></book><book id="2"><title>Emma</title></book></library>
Du får
status
XML er velformet.
formatert
<?xml version="1.0" encoding="UTF-8"?> <library> <book id="1"> <title>Dune</title> <year>1965</year> </book> <book id="2"> <title>Emma</title> </book> </library>

Each child element moves to its own line, two spaces deeper than its parent. Notice that the first line now also says encoding UTF-8, which the original did not state.

Kjørt med verktøyets egen kode.

Text mixed with tags stays on one line

Du skriver inn
XML
<p>Hello <b>big</b> world</p>
Du får
status
XML is well formed.
formatert
<?xml version="1.0" encoding="UTF-8"?> <p>Hello <b>big</b> world</p>

When an element holds text between its tags, adding line breaks could change the text. The tool leaves such an element exactly as it was, so only the declaration line is added.

Kjørt med verktøyets egen kode.

Tags that do not match

Du skriver inn
XML
<a><b></a>
Du får
status
XML is not well formed. Check the tags and quotation marks.
formatert

The element b is opened but never closed before a ends, so the parser rejects the whole document. The message does not give a line or column, so look for the nearest unclosed tag.

Kjørt med verktøyets egen kode.

Når det er nyttig

  • Make a minified feed, sitemap or configuration file readable before you edit it by hand.
  • Find out quickly whether a hand-edited XML file still parses, before you load it into another program.
  • Tidy an XML snippet for a bug report, a code review or documentation.
  • Check an exported file from an app for broken tags or unescaped characters.

Begrensninger

  • It checks well-formedness only. It cannot tell whether the elements and attributes follow an XSD schema or a DTD, so a file can pass here and still be rejected by a strict consumer.
  • Any document with a DOCTYPE is refused on purpose. Remove that line first if you only want the formatting.
  • The first line is always rewritten as version 1.0 with UTF-8. An original encoding such as ISO-8859-1, or a standalone flag, is dropped from the output.
  • An element that contains text next to other tags stays on one line. Repeated namespace declarations may also appear on child elements in the output, which is still valid XML but longer.

Tips

  • Fix errors from the top down. One missing closing tag early on can make every tag after it look wrong.
  • Escape the characters & and < inside text as &amp; and &lt;. A bare one is the most common cause of a not-well-formed message.
  • Keep the original file. The formatted copy changes the declaration line, so do not overwrite a source file that must stay byte for byte.

Kilder

Vanlige spørsmål

Sobre XML-formaterer og -validator.

How do I format XML online with this tool?

Paste the XML into the input box and press Format XML. If the text is well formed, the output box shows it with two-space indentation, one element per line, and a declaration line at the top.

Does this XML validator check against an XSD or DTD?

No. It only tests that the XML is well formed. A document can be well formed and still break the rules of a schema, so use a schema validator when that matters for your project.

Why does my DOCTYPE line cause an error?

The tool refuses documents with a DOCTYPE and its message says this is for safety. Delete the DOCTYPE line, format the rest, then add the line back to your own copy if you need it.

What is the difference between Format XML and Check XML?

Both run the same test. Format XML also fills the output box with the indented text. Check XML leaves the output empty and only reports whether the XML is well formed.

Why did my encoding declaration change?

The tool builds a new declaration line, always version 1.0 with UTF-8, instead of keeping the original. If your file must stay in another encoding, copy only the body and keep your own first line.

Is there a size limit?

Yes. The input can hold up to 2 MB, which is 2,097,152 characters. A larger document shows a message asking you to process a smaller one.

Is my XML uploaded to a server?

The page says the check happens in your browser with no upload. The text goes to the browser's built-in parser. Even so, take care with files that hold passwords or keys.

Hvordan bruker du XML-formaterer?

Lim inn XML for å kontrollere den, og gjør den deretter enklere å lese med ett klikk.

Lastes dataene mine opp til en server?

Nei. Behandlingen skjer i nettleseren din, og opplysningene dine lastes ikke opp.