What are the main purpose of using XML in Web pages?
XHTML itself is actually XML, but I think that is not what you are asking.
XML can be used to store data in a human-readable plain text format.
See the w3schools XML tutorial about XML for more info.
XML - eXtensible Markup Language - is a markup language designed to give a great amount of flexibility in marking up and passing around arbitrary data. In the web, XML is normally used for transporting data through feeds, API calls and the like. XML is also frequently used for configuration files for web frameworks such as Spring.
XML is - by name - extensible. As such it doesn't really have a main purpose. Maybe you should look at Wikipedia's List of XML Markup Languages? Or at the w3c Recommendation on XML, which stipulates the following design goals for XML:
- XML shall be straightforwardly usable over the Internet.
- XML shall support a wide variety of applications.
- XML shall be compatible with SGML.
- It shall be easy to write programs which process XML documents.
- The number of optional features in XML is to be kept to the absolute minimum, ideally zero.
- XML documents should be human-legible and reasonably clear.
- The XML design should be prepared quickly.
- The design of XML shall be formal and concise.
- XML documents shall be easy to create.
- Terseness in XML markup is of minimal importance.
Well, XML and its associated technologies have several uses/advantages:
Plain XML on its own is really just a plain-text data storage format. The well-formed criterion of the XML specification basically ensures that an XML document can always be parsed correctly. The tag structure of an XML document makes it easier to parse and access the content and, if you're interested in the semantic web, sort of makes it easier to find meaning in the data. XML (or markup languages derived from it) is used quite a lot in data transfer because it's an intermediate, platform independent format.
XML Schema can be used to enforce a particular structure and form in an XML document, and thus can be used to create custom markup languages.
XSL (or XML Stylesheets) can be used to generate a rendered output from any XML document that links to the stylesheet, so when someone loads the XML file in their browser it will display as XHTML or a PDF or whatever else you tell it to.