XML Interview Questions and Answers

What is XML?
XML stands for extensible markup language much like as a HTML. XML was designed to carry data, not to display data. XML loosely couples disparate applications or systems utilizing JMS, Web services etc. XML uses the same building blocks that HTML does: elements attributes and values. XML tags are not predefined. You must define your own tags.
Why is XML important?

Scalable: Since XML is not in a binary format you can create and edit files with anything and it's also easy to debug. XML can be used to efficiently store small amounts of data like configuration files (web.xml, application.xml, strutsconfig. xml etc) to large company wide data with the help of XML stored in the database. 
Fast Access: XML documents benefit from their hierarchical structure. Hierarchical structures are generally faster to access because you can drill down to the section you are interested in. 
Easy to identify and use: XML not only displays the data but also tells you what kind of data you have. The mark up tags identifies and groups the information so that different information can be identified by different application. 
Style ability: XML is style-free and whenever different styles of output are required the same XML can be used with different style-sheets (XSL) to produce output in XHTML, PDF, TEXT, another XML format etc. 
Linkability, in-line usability, universally accepted standard with free/inexpensive tools

Describe the differences between XML and HTML?

XML HTML
designed to transport and store data, with focus on what data is designed to display data, with focus on how data looks
User definable tags Defined set of tags designed for web display
Content driven Format driven
End tags required for well formed documents End tags not required
Quotes required around attributes values Quotes not required
Slash required in empty tags Slash not required

 

Is XML meant to replace HTML?

No, they both go together one is for describing data while other is for displaying data.

What is CDATA section in XML?

All data is normally parsed in XML but if you want to exclude some elements you will need to put those elements in CDATA.

What is XSL?
XSL (the extensible Style sheet Language) is used to transform XML document to some other document. So its transformation document which can convert XML to some other document. For instance you can apply XSL to XML and convert it to HTML document or probably CSV files.
Is XML case sensitive?
XML tags are case sensitive. The tag is different from the tag .

What is DOM?
A DOM (Document Object Model) defines a standard way for accessing and manipulating documents. The XML DOM defines a standard way for accessing and manipulating XML documents. The XML DOM views an XML document as a tree-structure. All elements can be accessed through the DOM tree. Their content (text and attributes) can be modified or deleted, and new elements can be created. The elements, their text, and their attributes are all known as nodes.
Define DTD (Document Type definition)?
DTD - Document Type Definition defines the legal building blocks of an XML document. It defines the document structure with a list of legal elements and attributes. XML DTD is a rule book that an XML document follows. Once DTD is ready, you can create number of XML documents following the same rules specified in the DTD. DTD can be internal or external DTD. The internal DTD is included in the XML document, while external DTD exists outside the content of the documents.
Explain DTD and schema?

A DTD provides a list of the elements, attributes, comments, notes, and entities contained in an XML or HTML document and indicate their relationship with each other. 

DTD supports two types of data - CDATA and PCDATA.
Schema means the organization and the structure of a database. Schema supports numeric, Boolean and String data types and suitable for applications that developed in a programming language. Schema supports custom data types. Schema supports encapsulation and inheritance concepts. Schema supports for WEB services, XSLT.

E.g.: An XML schema is a description of XML document. It is expressed in terms of constraints on the structure and content of documents.

What are the standard ways of parsing XML document? or What is a XML parser?

XML parser sits in between the XML document and the application who want to use the XML document. Parser exposes set of well defined interfaces which can be used by the application for adding, modifying and deleting the XML document contents. 

There are two standard specifications which are very common and should be followed by a XML parser:- 

DOM: - Document Object Model.
IT is an open standard. The XML file is arranged in a tree fashion. DOM supports random access to the data of XML file. 
DOM is a W3C recommended way for treating XML documents. In DOM we load entire XML document into memory and allows us to manipulate the structure and data of XML document. 

SAX: - Simple API for XML. 
SAX is event driven way for processing XML documents. In DOM we load the whole XML document in to memory and then application manipulates the XML document. But this is not always the best way to process large XML documents which have huge data elements. For instance you only want one element from the whole XML document or you only want to see if the XML is proper which means loading the whole XML in memory will be quiet resource intensive. SAX parsers parse the XML document sequentially and emit events like start and end of the document, elements, text content etc. So applications who are interested in processing these events can register implementations of callback interfaces. 
SAX parser then only sends those event messages which the application has demanded. 

In What scenarios will you use a DOM parser and SAX parser?

If we do not need all the data from the XML file then SAX approach is much preferred than DOM as DOM can quiet memory intensive. In short if you need large portion of the XML document its better to have DOM. 
With SAX parser you have to write more code than DOM. 
If we want to write the XML in to a file DOM is the efficient way to do it. 
Some time you only need to validate the XML structure and do not want to retrieve any Data for those instances SAX is the right approach. 

Latest Updates

General Knowledge of India

In 1897, the Birsa Movement supporters raised which colour flag as a symbol of Birsa Raj?

Ratio and Proportion

The cost of 10 books is Rs. 80/-. Find the value of 15 books?

The cost of 48 bags of paddy is Rs. 16,800/-. What is the cost of 36 bags of paddy?

Monthly expenditure of a family of 4 members is Rs 2800/-. What is the expenditure if there are 3 members in the family?

Annual incomes of the families of Sita and Latha are in the ratio 4:3 and their annual expenditure are in the ratio 3:2. What is their annual income if they save Rs. 3000/- in a year?

A certain sum of money is divided between A and B in the ratio of 5/4 : 5/3 and A got Rs. 360/-. Find the total sum of money and B’s share?

In an office, the ratio of the salaries of an officer and a clerk is 15:7. If the salary of a clerk is Rs. 720/- less than the salary of the officer, find the salary of each?

In an election to a municipal council, the votes secured by two candidates are in the ratio 13:19. The elected candidates gets 312 votes more than the second candidate. How many votes are secured by the second candidate?

A certain sum of money is divided between Murthy and Prasad in the ratio 22/7 : 8/3. If Murthy gets Rs. 120/- more than Prasad, find the share of each?

In a cricket test series, the runs made by Raju and Tendulkar are in the ratio 5:9 and Tendulkar and Azar are in the ratio 6:7. What are the runs made by them if Azar makes 187 runs more than Raju?

If A:B = 2:3 and B:C = 9:5 find A:B:C?

If A:B = 3/5:5/7 and B:C = 3/4:2/5, find A:B:C?

If R:S = 0.01:0.11 and S:T = 2.2:1, Find R:S:T?

In a school, Under a Saving Scheme, Rekha saves 3/2 times the savings of Bindu, Geeta saves 4 times the savings of Rekha. Find the ratio of the savings of all the three in least terms?

Simplification

A man left 1/3 rd of his property to his wife and 3/5 th of the remainder to his daughter. He gave the rest to his son who received Rs. 6400/-. How much was his original property worth?

Ratio and Proportion

In a school 4/9 of the pupils are boys. There are 125 girls. How many boys are there?

If A:B = 3:4 and B:C = 5:6, find A:C?

IF X:Y = 3:4 AND Y:Z = 4:5, FIND X:Y:Z?