Skip to content
Related Articles
Open in App
Not now

Related Articles

How to check the structure of an XML Document ?

Improve Article
Save Article
  • Last Updated : 26 Jul, 2021
Improve Article
Save Article

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"?>
   <name>Tanya Bajaj</name>

XML document has 2 sections:

  • Document Prolog: It contains XML & document type declaration (First 2 lines in the above XML doc).
  • Document Elements: The building components of XML are Document Elements. These sections divide the document into a hierarchy of sections, each with its own utility.

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:

  • An optical title, a given name, and a surname make up a person’s name.
  • One or more channels can be found on a television schedule. There are one or more time slots on each channel. There is a program title and an optional description for each time slot.

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. 

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!