XML - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

XML Whitespaces

XML Whitespaces

shape Description

XML Whitespaces consists of carriage returns, line feeds, tabs and space of characters that are encoded in documents. Normally, Whitespaces are used to make the documents more readable wherever required. An XML Parser ignores white space unless it is inside an element, then it passes the white space along to the application as a part of the character data for the element. XML spec tells try not to guess what the white space means. So, XML defines a pre-defined attribute xml:space to control what happens. Now regardless of what the attribute is set for, the Parsers are always going to pass the white space along to the underlying application because that's what the XML spec has to do and its upto the application to decide what it wants to do with white space it encounters. There are two values that can be specified to xml:space attribute. 1) string "default" in which the application should just use whatever its default settings are for handling whitespace. 2) "preserve" which tells the application that it should try to preserve all the white spaces that it comes across regardless of where it sees inside the elements.

Whitespaces Types

shape Description

XML document normally has two types of Whitespaces. They are:

Significant Whitespace

A significant Whitespace will have text and markup combinedly presents inside an element. For example, [xml] <name>SPLessonsXML</name> [/xml] and [xml] <name>SPLessons XML</name> [/xml] The above mentioned two elements are completely different due to presence of whitespace between the two strings.

Insignificant Whitespace

Insignificant whitespace allows only the content in the space. For Example, [xml] <address.category="residence"> [/xml] or [xml]<address....category="..residence">[/xml] Above mentioned elements are same in which space is given by using dots(.).

Summary

shape Key Points

  • XML Whitespaces consists of carriage returns, line feeds, tabs and space of characters.
  • The attribute xml:space decides to remove whitespace or not.
  • Significant and Insignificant Whitespaces are the types of Whitepaces.