In this article, you will see list of XML interview questions with answers, which can help you learn more about XML before proceeding for any technical interview.
1. What is XML?
XML stands for Extensible Markup Language, it can be used to transfer data between services like Web API and Front-end of any website.
XML is a simple and flexible markup language in text format.
XML is basically used to decribe data and it also support user defined tags.
Example of XML
<?xml version="1.0" encoding="UTF-8"?> <book> <name>A Song of Ice and Fire</name> <author>George R. R. Martin</author> <language>English</language> <genre>Epic fantasy</genre> </book>
2. What can be alternative of XML?
JSON can be used as an alternative of XML, although now a days JSON is preferred but XML is still widely used in data-processing between the internet.
3. What is difference between XML and HTML?
Here are the difference between XML and HTML
- XML is used to describe the data and transfer data, while HTML is mark-up language used to show data.
- XML is case-senstive while HTML is not.
- XML supports user-defined tags while HTML has pre-defined tags.
- XML is content driven, whereas HTML is format driven
- XML provides namespaces support while HTML doesn't provide namespaces support.
- In XML we need to close tags, while HTML it is not true for all tags.
4. What is XML schema (XSD)?
XML Schema Definition (XSD) language is the current standard schema language for all XML documents and data.
The XML Schema definition language (XSD) enables you to define the structure and data types for XML documents.
An XML Schema defines the elements, attributes, and data types that conform to the World Wide Web Consortium (W3C) XML Schema.
An XML Schema is composed of the top-level schema element.The schema element contains type definitions (simpleType and complexType elements) and attribute and element declarations.
5. What are the disadvantages of using XML?
- XML requires a processing application
- Cannot create custom tags.
- Requires more data processing power and traffic for small amount of useful data, like below example, where information is just 1 byte
<CustomerOrderMessage> <OrderNumber>1</OrderNumber> </CustomerOrderMessage>?
- Too many tags for a single document structure could interfere with XML's ability to process the information.
- No intrinsic data type support
6. What is DTD?
DTD stands for Description of Type of Document and it is used to define building blocks of XML.
DTD defines rules for a specific type of document as below:
- Names of elements
- Order of elements
- Proper nesting and containment of elements
- Element attributes
7. How do you execute an XML file?
This is trick question, an XML file can not be executed or run. You can open it or View it but you cannot execute it. You can open and view file using any XML editor or even using Notepad.
8. What is element, attribute and namespace in XML?
Element: XML Elements are represented by tags and it explains about the data, like
<language>English</language>, Where language is element
Attribute: It specifies more details of any XML element, for example, in below XML "id" is an attribute of element "order"
<Order id="1"> <Price> 2300</Price> <Order>
Namespace: XML namespace are basically used to avoid clash between two similar XML's, it's just like we provide namespace to any class in C# or provide package in Java.
9. What is SOAP and how does it relate to XML?
The Simple Object Access Protocol (SOAP) uses XML to define a protocol for the exchange of information in distributed computing environments.
SOAP consists of three components: an envelope, a set of encoding rules, and a convention for representing remote procedure calls.
Unless experience with SOAP is a direct requirement for the open position, knowing the specifics of the protocol, or how it can be used in conjunction with HTTP, is not as important as identifying it as a natural application of XML.
10. What is XPath (Considering XML)?
The XPath language is based on a tree representation of the XML document, and provides the ability to navigate around the tree, selecting nodes by a variety of criteria.
In popular use, an XPath expression is often referred to simply as "an XPath", which defines a pattern or path expression to select nodes or node sets in an XML document.
XPath specifies seven types of nodes that can be output of the execution of the XPath expression.
- Processing Instruction
<?xml version="1.0" encoding="utf-8"?> <Wikimedia> <projects> <project name="Wikipedia" launch="2001-01-05"> <editions> <edition language="English">en.wikipedia.org</edition> <edition language="German">de.wikipedia.org</edition> </editions> </project> <project name="Wiktionary" launch="2002-12-12"> <editions> <edition language="English">en.wiktionary.org</edition> <edition language="French">fr.wiktionary.org</edition> </editions> </project> </projects> </Wikimedia>
Then Xpath for selects name attributes for all projects, will be
11. Can we have empty XML tags?
Yes, we can have empty tags in XML. It allows us to show that tag doesn't have any content, you can represent it as below
<student></student> <!--OR--> <student/>
12. How can I include conditional statements in XML?
We cannot do that, but we can use DTD (Document Type Definition) to include conditional statements.
<xsl:if test="@foo=’bar’"> <xsl:text>Hello, world!</xsl:text> </xsl:if>
13. What are the special characters used in XML?
<, > and & are the special characters used in XML. Because these characters are used for making tags.
14. What is XQuery?
XQuery is to XML what SQL is to databases. XQuery is designed to query XML data. We can also Transform XML data to XHTML using XQuery.
15. Can we use graphics in XML?
Yes, graphics can be stored in XML file by using XLink and XPointer. It supports graphics like GIF, JPG, TIFF, PNG, CGM, EPS, SVG.
You may also like to read: