Open In App

How to check the structure of an XML Document ?

Introduction : XML document is a well-organized collection of components and associated markup. An XML document can hold a wide range of information.  For instance, a database having numbers or a mathematical equation etc.

Example: A simple document can be created as –



<?xml version = "1.0"?>
<Student-info>
   <name>Tanya Bajaj</name>
   <Organization>GeeksForGeeks</Organization>
   <contactNumber>(+91)-9966778909</contactNumber>
</Student-info>

XML document has 2 sections:

Can the structure of the XML Document be checked somehow?
A tool for creating rules that regulate how documents are constructed is included in XML. These are referred to as DTDs (Document Type Definitions) in jargon. You may set up a DTD to check XML documents automatically in a variety of ways. Here is a couple of such examples:



These effects can be achieved by identifying the element types that you want to employ in your document and indicating the structural order in which they can appear in the document type. A utility called an XML Parser is then able to test whether or not the document meets the prescribed rules.

Checking the structure of XML Doc using XML Parser

An XML parser is a software library or package that provides client applications with interfaces for working with XML documents. In other words, The XML parser is a program that reads XML and allows a program to use it. The XML parser checks the document and ensures that it is properly formatted. XML parsers are included in most modern browsers. 

What if we do not want our structure checked?
No problem; with XML, it’s completely acceptable not to double-check your documents’ structure against a DTD. The document is regarded as a well-formed XML document if the elements nest properly within each other, providing a tree-like structure. 
Because they can be processed using simple XML tools, well-formed XML documents are particularly well suited for Internet use. These tools are compact and light enough to be employed in a variety of applications, including browser applets, credit card swipers, and laboratory equipment. 

Article Tags :