What is XML parsing?

What is XML parsing in Android?

Extensible Mark-up Language, abbreviated as XML is a very popular format and commonly used for sharing data on the internet. Android DOM(Document Object Model) parser is a program that loads the XML file into the Android memory, parses it and extracts the required information from it. This parser uses an object-based approach for creating and parsing the XML files. This results in more consumption of memory. The document is parsed through every possible node in the XML file. The XML file that contains the information to be extracted includes the following four main components:

  • Prolog: The XML file will start with a prolog. Prolog contains the information about a file, which is available in the first line.
  • Events: Events such as document start and end, tag start and end, etc. are contained in the XML file
  • Text: It is a simple text present in between the opening and closing XML tag elements.
  • Attributes: They are the additional properties of a tag present within the label.

Types of XML Parsers

  • DOM Parser.
  • SAX Parser.
  • JDOM Parser.
  • Stax Parser.
  • Xpath Parser.

Out of these many parsers, Android provides three types of XML parsers, namely, DOM, SAX and XMLPullParser. Among all of them, XMLPullParser is recommended by android because it is easier to use and relatively more efficient.