Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importance of indenting XML file

Tags:

xml

Is it necessary to indent the XML tags in a XML file for successful parsing of the file?

like image 887
Abhinav Avatar asked Sep 21 '12 07:09

Abhinav


People also ask

What is the advantage of formatting and indenting your markup XML?

How Oxygen XML Author formats and indents XML. You can control how Oxygen XML Author formats and indents XML documents. This can be particularly important if you store your XML document in a version control system, as it allows you to limit the number of trivial changes in spacing between versions of an XML document.

Why are XML files important?

To summarize: An XML file is a file used to store data in the form of hierarchical elements. Data stored in XML files can be read by computer programs with the help of custom tags, which indicate the type of element.

How do I correct an indentation in XML?

To turn it on or off for the Text editing mode,open the Preferences dialog box (Options > Preferences), go to Editor > Format > XML, and select/deselect the Schema-aware format and indent option.

Does XML care about tabs?

XML translates non-space characters (tab and new-line) into a space character and consolidates all multiple space characters into a single space. XML ignores the sequence of white space occurring between two elements if the parent element is defined to have element content.


2 Answers

No, the XML spec define whitespace like this:

In editing XML documents, it is often convenient to use "white space" (spaces, tabs, and blank lines) to set apart the markup for greater readability. Such white space is typically not intended for inclusion in the delivered version of the document. On the other hand, "significant" white space that should be preserved in the delivered version is common, for example in poetry and source code.

So in terms of parsing the document, no. You can use as much or as little as you want or need and it will parse correctly. This may or may not change the meaning of the XML document, however.

Indenting XML tags is never required for parsing. However, the point of XML is to be human as well as machine readable, so indentation is generally worth having, as it makes it far easier for human readers to work with and take in the structure at a glance.

like image 177
Gareth Latty Avatar answered Sep 20 '22 21:09

Gareth Latty


Short, short, short answer: Nope.

Longer answer: It depends on your application whether or not whitespace is significant. If you indent your XML file you add whitespace which sometimes has meaning to the application processing the data contained.

But for parsing the XML file? Whitespace does not influence the parse-ability, no. See the whitespace handling section of the XML specification.

like image 31
Martijn Pieters Avatar answered Sep 22 '22 21:09

Martijn Pieters