- XML Tutorial
- XML - Home
- XML - Overview
- XML - Syntax
- XML - Documents
- XML - Declaration
- XML - Tags
- XML - Elements
- XML - Attributes
- XML - Comments
- XML - Character Entities
- XML - CDATA Sections
- XML - White Spaces
- XML - Processing
- XML - Encoding
- XML - Validation
- Advance XML
- XML - DTDs
- XML - Schemas
- XML - Tree Structure
- XML - DOM
- XML - Namespaces
- XML - Databases
XML - WhiteSpaces
In this chapter, we will discuss whitespace handling in XML documents. Whitespace is a collection of spaces, tabs, and newlines. They are generally used to make a document more readable.
XML document contains two types of whitespaces - Significant Whitespace and Insignificant Whitespace. Both are explained below with examples.
A significant Whitespace occurs within the element which contains text and markup present together. For example −
The above two elements are different because of the space between Tanmay and Patil. Any program reading this element in an XML file is obliged to maintain the distinction.
Insignificant whitespace means the space where only element content is allowed. For example −
<address.category = "residence">or
<address....category = "..residence">
The above examples are same. Here, the space is represented by dots (.). In the above example, the space between address and category is insignificant.
A special attribute named xml:space may be attached to an element. This indicates that whitespace should not be removed for that element by the application. You can set this attribute to default or preserve as shown in the following example −
<!ATTLIST address xml:space (default|preserve) 'preserve'>
The value default signals that the default whitespace processing modes of an application are acceptable for this element.
The value preserve indicates the application to preserve all the whitespaces.
Kickstart Your Career
Get certified by completing the courseGet Started