In this guide we will cover the top most XML interview questions and answers that will help you in giving an interview like a pro.
What is an XML?
An XML stands for eXtensible Markup Language, which used to store the data. It does not have a predefined structure like a HTML language but you can customize an XML tags. It mainly has a hierarchical structure, conceptually a tree structure called as an XML tree.
What are the most popular Markup Languages?
There are two most popular and widely used markup languages, i.e. HTML and XML. Here is the list of the other languages that are also used in the programming:
-
- HTML – Hypertext Markup Language
- XHTML – eXtensible Hypertext Markup Language
- XML – eXtensible Markup Language
- MathML – Mathematical Markup Language
- SGML – Standard Generalized Markup Language
- KML – Keyhole Markup Language
What are the main features of an XML?
- An XML files are plain text files and it does not require any particular programming IDE
- It is easy to learn and implement
- It does not have complex programming rules and has a very limited syntax
What is the difference between XML and HTML?
You can compare the both markup languages from the given points:
HTML | XML |
It is a markup language that is used to display data on browser | It is a markup language that is used to store data on the computer |
It is a case sensitive language | It is a case insensitive language |
It is used for web designing | It is used to send or receive and storing data |
It has predefined tags to display web pages | It has custom tags to store data |
There is no impact of white spaces and it does not store any of it | It stores white spaces |
It has a static structure | It has a dynamic structure |
It does not require stylesheets | Stylesheets or XSL is mandatory for the formatting of data |
What is an XML DOM Document?
An XML DOM (Document Object Model) depicts the entire representation of an XML document. It gives complete access to the root and elements, and allows you to read and change the content of a document.
What are the advantages of an XML DOM Document?
- An XML DOM gives you a standard way to access the whole document by presenting it as a tree structure
- An XML DOM provides you to read, manipulate and change an XML document
What is an XPath?
XML Path is a syntax to define the parts of an XML document. It has path expressions to navigate to the required node of a document.
What are the rules for creating good XML?
You need to follow the following rules in order to have a good XML document:
- There must be a root element
- XML opening tags must be followed by the same closing tag
- The nested XML tags must be properly handles and follow the same structure
- XML tag names are case sensitive
- XML tag names have limit
- XML tag names cannot have white spaces
- Attributes are given in quotation marks “”
- Whitespaces are preserved
What is an XML Element?
An XML element is considered as the basic building blocks of an XML document. It is used as a container to store text elements and data. It can have other elements as a part of the main element.
Example:
<name>An XML Guideline</name>
What is an XML Attribute?
An XML attribute is quoted in quotation marks for text strings and URLs. You can use single or double quotation marks or even the combination of both.
Example:
<student gender=”male”> or <student gender=’female’>
What is an XML Namespace?
An XML namespace is a collection of elements or attributes in an XML document. It is used to avoid conflicts between the multiple elements having the same name in a document.
What is an XML Parser?
An XML parser is library or a utility package that is used to provide the medium between client and an XML document. It validates an XML document by checking the proper format of it. The main goal of a parser is to transform an XML code into a readable code.
What is an XSL?
An XSL is a language used to display an XML document for the given type. It is used with XML to express the style just like the CSS stylesheets.
What is an XML Schema?
An XSL Schema provides the complete definition of an XML document. It is commonly known as an XML Schema Definition (XSD). It is similar to the schema of a database.
What does XML Schema has?
It contains the following properties:
- Elements and its attributes
- Elements having child elements in it
- Elements order or child elements order
- Data types of elements and child elements
What is an XSL?
An XSL, stands for eXtensible Stylesheet Language, is a language used to display an XML document for the given type. It is used with XML to express the styles in an XML document in the same way as HTML has CSS stylesheets to do the formatting of web pages.
What are the three parts of XSL?
An XSL has the following three parts:
- XSLT – To transform an XML documents
- XPath – To navigate in an XML documents
- XSL-FO – To format an XML documents
What are the differences between XML DTD and XSD?
Following are the differences between XML DTD (Document Type Definition) and XSD:
XML DTD | XSD |
It does not support namespaces | It supports namespaces |
It does not support datatypes | It has a provision to support datatypes for elements and attributes |
It is derived from SGML syntax | It is written in an XML format |
What is an SGML?
The Standard Generalized Markup Language (SGML) is used as a standard to define further markup languages for documents.
How do you add comments in an XML document?
You can add comments as <!- your comments here -> as like HTML. The comment symbol is applicable for both single and multiple lines.
How can you execute an XML document?
An XML is a markup language that is used to represent a data. It is not a program that is written in programming language to execute.
What are the special characters in an XML document?
An angular brackets <,> and & are the special characters in an XML document as these are used for generating an XML tags in a document.
How can you replace HTML with XML and vice versa?
You cannot replace HTML with XML and vice versa. They both provide different meanings in their approaches. The HTML is used for web designing whereas an XML is used to store the data.
What is an XQuery?
XQuery or XML Query is a functional programming language, to extract the elements and attributes from an XML document. The working group of XML W3C developed this language in 2017.
Why do you need an XML editor?
An XML editor is used to write error free XML documents. It helps in validating an XML DTD or schema by performing the following actions:
- It checks the opening and closing of an XML tags
- It validates an XML against schema
- It provides a color coding on XML syntax
- It validates the DTD
What is an XML Encoding?
An XML encoding is a way to transforming Unicode characters into the binary representation of the elements. The conversion depends on the type of encoding being used in a document.
What are the types of an XML Encoding Error?
An XML Encoding error is thrown as an ‘Encoding Error’ when there is an error in an XML file. There are two types of XML encoding error:
- Invalid character
This type of encoding error will occur if an XML document contains non-ASCII characters, and an XML file is saved with a single byte ANSI encoding technique.
- Different Encoding Techniques
This type of error will occur if there is a mismatch in the encoding technique used at the time of creating an XML document.
What are the differences between Simple and Complex Elements?
Following are the differences between a simple and complex element:
Simple Element | Complex Element |
It cannot have any empty element | It can have empty elements |
It cannot contain any other element | It has a provision to contain other elements |
It can only support text | It can support text and other elements |
How to display a XML data in an HTML page?
You can use javascript to display the content of an xml document.
<?XML version="1.0"?>
<class>
<student id="std101">
<name>Student A</name>
<gender>Male</gender>
<age>25</age>
<department>Department A</department>
<joiningdate>9999-99-99</joiningdate>
</student>
<student id="std102">
<name>Student B</name>
<gender>Male</gender>
<age>25</age>
<department>Department A</department>
<joiningdate>9999-99-99</joiningdate>
</student>
</class>
HTML Page to display list of students from an XML document using javascript:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Display XML List on HTML Page</title> </head> <body> <div id='parent'> <table id='students'> <thead> <tr> <th>Student ID</th> <th>Student Name</th> <th>Student Gender</th> <th>Student Age</th> <th>Student Department</th> <th>Student Joining Date</th> </tr> </thead> <tbody> </tbody> </table> </div><script type='text/javascript'> let XMLContent = ''; let studentsList = document.getElementById('students'); fetch('students.XML').then((response)=> { response.text().then((XML)=>{ XMLContent = XML; let parser = new DOMParser(); let XMLDOM = parser.parseFromString(XMLContent, 'application/XML'); let students = XMLDOM.querySelectorAll('student'); students.forEach(studentXMLNode => { let row = document.createElement('tr'); //student ID let td = document.createElement('td'); td.innerText = studentXMLNode.children[0].innerHTML; row.appendChild(td); // student Name td = document.createElement('td'); td.innerText = studentXMLNode.children[1].innerHTML; row.appendChild(td); // student Gender td = document.createElement('td'); td.innerText = studentXMLNode.children[2].innerHTML; row.appendChild(td); // student Age td = document.createElement('td'); td.innerText = studentXMLNode.children[3].innerHTML; row.appendChild(td); // student Department td = document.createElement('td'); td.innerText = studentXMLNode.children[4].innerHTML; row.appendChild(td); // student JoinignDate td = document.createElement('td'); td.innerText = studentXMLNode.children[5].innerHTML; row.appendChild(td); studentsList.children[1].appendChild(row); }); }); }); </script> </body> </html>
What do you use XML Data Binding?
An XML data binding is the process of reading and writing an XML data using a programming language. It usually process using a class library (like Java, C# etc.), precisely for the given format of an XML document.
If you create an XML data binding in an application, the application can access the data with an XML instead of depending on the Document Object Model (DOM) and retrieve the data from an XML file.
What is an XML Signature?
An XML Signature is a method of creating an association for digital signatures.
How to create an XML Signature?
You can create an XML signature by following the given steps:
- You need to determine which resources are to signed by using Uniform Resource Identifier
- You need to calculate the size of each resource
- You need to collect the reference elements of an XML document
- Next is the Signing phase
- After signing, you need to add the key information
- In the last, you need to enclose it in a signature element
What is an XML Sitemap?
An XML Sitemap refers to the structure of the important pages in a website.