XML Interview Questions and Answers

 Q1. What is XML ?
XML (Extended Markup Language) is a metalanguage which allows users to define their own customized markup languages, especially in order to display documents on the Internet.

Q2. What are the Differences Between XML and HTML 

XML HTML
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

Q3. What is Document Type Definition (DTD)?
DTD is known as Document Type Definition, which provides a description of a document written in XML. DTD consists of XML declaration syntax. It also defines the naming convention rules for different types of element. If you want to describe the lists consisting of some items then DTD will look like:
<!ELEMENT List (Item)+> // Element list contains one or more items (+)
<!ELEMENT Item (#PCDATA)> // element types contains plain text (Parsed Character Data or PCDATA).

Q4. What is DOM and how does it relate to XML?
The Document Object Model (DOM) is an interface specification maintained by the W3C DOM Workgroup that defines an application independent mechanism to access, parse, or update XML data. In simple terms it is a hierarchical model that allows developers to manipulate XML documents easily Any developer that has worked extensively with XML should be able to discuss the concept and use of DOM objects freely. Additionally, it is not unreasonable to expect advanced candidates to thoroughly understand its internal workings and be able to explain how DOM differs from an event-based interface like SAX.

Q5. What are the related specifications of XML?
XML stands for Extensible Markup language which is designed to transport and store data. The related specification of it as follows:

  •  XML Namespaces: allows easy to store XML elements and attributes for a document.
  • XML Base: set the base for resolution of relative URI references. It defines xml:base attribute.
  •  XML information/infoset: describes an abstract data model for XML documents.
  •  XPath: defines a syntax which identifies one or more internal components (elements, attributes, etc) included in XML document.
  •  XSLT: is a language with an XML-based syntax that is used to transform XML documents into XML or other formats.
  •  XQuery: allows easy to use methods to access, manipulate and return XML in XML databases.
  •  XML Signature/Encryption: defines syntax and processing rules for creating and encrypting digital signatures on XML content.

Q6. 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.

Q7. Describe the role that XSL can play when dynamically generating HTML pages from a relational database.
Even if candidates have never participated in a project involving this type of architecture, they should recognize it as one of the common uses of XML. Querying a database and then formatting the result set so that it can be validated as an XML document allows developers to translate the data into an HTML table using XSLT rules. Consequently, the format of the resulting HTML table can be modified without changing the database query or application code since the document rendering logic is isolated to the XSLT rules.

Q8. How are documents accessed and manipulated in XML?
The XML DOM (document object model) is used the access and management of xml. It is a platform that is language neutral and allows a program or a script to dynamically access a document. It also allows the updation of content as well as the structure and style of the document. It is responsible for the defining of the object and properties of all xml elements as well as to define the methods for their access.
There are various methods that can be used in xml dom such as:
1. getElementsByTagName : Used to call a specific user defined tag.
2. setAttribute : Used to change the value of an existing attribute.
3. appendChild : Used to add a child node to another node.

Q9. Give a few examples of types of applications that can benefit from using XML.
There are literally thousands of applications that can benefit from XML technologies. The point of this question is not to have the candidate rattle off a laundry list of projects that they have worked on, but, rather, to allow the candidate to explain the rationale for choosing XML by citing a few real world examples. For instance, one appropriate answer is that XML allows content management systems to store documents independently of their format, which thereby reduces data redundancy. Another answer relates to B2B exchanges or supply chain management systems. In these instances, XML provides a mechanism for multiple companies to exchange data according to an agreed upon set of rules. A third common response involves wireless applications that require WML to render data on hand held devices.

Q10. How is metadata handled by xml?
The xml does not contain any predefined elements. Xml generally in broad terms is considered to be an architecture and not an application. Due to this reason it is not the responsibility of xml to specify how metadata is to be implemented. It is left up to the user to select how to implement metadata. Most browsers have their own way of specifying a method to handle metadata. The xml metadata interchange is used as a standard way for users to exchange information pertaining to metadata. The metadata information is usually stored in the form of attributes.
For Example:
<messages>
<note id=”501″>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don’t forget me this weekend!</body>
</note>
<note id=”502″>
<to>Jani</to>
<from>Tove</from>
<heading>Re: Reminder</heading>
<body>I will not</body>
</note>
</messages>

Q11. What is the use of annotations in reference to an xml document?
The annotations are used in a xml document to provide additional information about the xml document. The annotation element can be followed by a documentation element to make it understandable to a user (human). In case an annotation element is followed by an appInfo element then the information is meant to be used by an application.
Example of an annotation followed by document element:

<xsd:element name=”books”>
<xsd:annotation>
<xsd:documentation xml:lang=”en”>
This is a collection of best-selling books.
</xsd:documentation>
</xsd:annotation>
</xsd:element>

Q12. How are white-spaces handled by xml?
Any white-space ( this includes line breaks, tab characters and normal spaces etc.) are passed by the xml parser unchanged to an application. This implies that it is not the responsibility of a parser on how to interpret a white-space, instead it is the responsibility of the application to know what to do with it. The white-spaces in xml can be broadly categorized into two types:

1. Insignificant white-space : Those whites-paces that are found between structural elements and are passed by the parser as they are to the application without any effect ( suppressed) are the insignificant spaces. A good example of such white-spaces are the spaces given in an html document.
2. Significant white-space : Those spaces that occur between the elements and can contain text and markup mixed together and are passed by the parse exactly the way they are to the application for their handling are known as the significant white-spaces.

Q13. What are the advantages of using Xforms over HTML?
The Xforms is an application that has been created by the abc. The xforms application enables the separation of presentation and content. It also provides the user with expanded form capabilities. The advantages of using the xforms over html forms are as follows:1. The data related to the form can be submitted and collected in the form of xml.
2. It allows external xml documents to be loaded as initial form data.
3. The xforms support xpath expressions and can also support xml schema datatypes.
4. This application can be integrated with different web services.
5. The application of xforms is device independent.
6. It also supports / provides a few more additional features such as:
– Capability to specify initial value for form data.
– Switch element for form completion etc.

Q14. When constructing an XML DTD, how do you create an external entity reference in an attribute value?
Every interview session should have at least one trick question. Although possible when using SGML, XML DTDs don’t support defining external entity references in attribute values. It’s more important for the candidate to respond to this question in a logical way than than the candidate know the somewhat obscure answer.

Q15. How would you build a search engine for large volumes of XML data?
The way candidates answer this question may provide insight into their view of XML data. For those who view XML primarily as a way to denote structure for text files, a common answer is to build a full-text search and handle the data similarly to the way Internet portals handle HTML pages. Others consider XML as a standard way of transferring structured data between disparate systems. These candidates often describe some scheme of importing XML into a relational or object database and relying on the database’s engine for searching. Lastly, candidates that have worked with vendors specializing in this area often say that the best way the handle this situation is to use a third party software package optimized for XML data.
Obviously, some important areas of XML technologies were not included in this list — namespaces, XPointer, XLink, and so on — and should be added to the interviewer’s set of questions if applicable to the particular position that the candidate is applying for. However, these questions in conjunction with others to assess soft skills (communication skills, ability to work on teams, leadership ability, etc.) will help determine how well candidates understand the fundamental principles of XML.

Q16. When should I use a CDATA Marked Section?
CDATA is used to let an author to quote fragments of text, containing markup characters. CDATA is not used to preserve embedded markup characters. You use it when you want to design according to your need, like writing documentation etc. For example:-
“Text to write here”<![CDATA[<em>markup</em>]]>

Q17. While writing an xml document what are the rules that are to be followed?
Since xml does not have any predefined tags or elements there are not much problems in writing an xml document. Although there are a few rules that should be kept in mind while writing the document such as:

  • The tags in xml once opened should also must be closed.
  • All the tags in xml are case sensitive.
  • All xml elements must be properly nested.For Example:<home>
    <room>
    ….
    ….
    </room>
    </home>- The entire document must contain a root node which would contain all the tags defined in the document within it.
    – Any attribute values must be specified between quotes.

Q18. What is the role of the doctype declaration in reference to XML?
The doctype has several purposes in an xml document such as:
1. It is used for validation purposes of the document.
2. It helps the browser to tell which version of the markup language was used by the creator.
3. The doctype helps in rendering a page properly in a browser that is standards compliant.The doctypes can be differentiated into three major types:strict doctype declaration : This declaration is used when css is being used to style a page.
transactional doctype declaration : This doctype specification is used if the document consists of any presentational markups.
frames doctype declaration : This is used id the document is present in form of frames.

Q19. Can you walk us through the steps necessary to parse XML documents?
Superficially, this is a fairly basic question. However, the point is not to determine whether candidates understand the concept of a parser but rather have them walk through the process of parsing XML documents step-by-step. Determining whether a non-validating or validating parser is needed, choosing the appropriate parser, and handling errors are all important aspects to this process that should be included in the candidate’s response.

Q20. Give some examples of XML DTDs or schemas that you have worked with.
Although XML does not require data to be validated against a DTD, many of the benefits of using the technology are derived from being able to validate XML documents against business or technical architecture rules. Polling for the list of DTDs that developers have worked with provides insight to their general exposure to the technology. The ideal candidate will have knowledge of several of the commonly used DTDs such as FpML, DocBook, HRML, and RDF, as well as experience designing a custom DTD for a particular project where no standard existed.

Q21. Using XSLT, how would you extract a specific attribute from an element in an XML document?
Successful candidates should recognize this as one of the most basic applications of XSLT. If they are not able to construct a reply similar to the example below, they should at least be able to identify the components necessary for this operation: xsl:template to match the appropriate XML element, xsl:value-of to select the attribute value, and the optional xsl:apply-templates to continue processing the document.
Extract Attributes from XML Data
Example 1.
<xsl:template match=”element-name”> Attribute Value: <xsl:value-of select=”@attribute”/> <xsl:apply-templates/> </xsl:template>

Q22. What are the different formatting objects in XSL-FO are categorized into?
The XSL-FO is used to specify how the content of a structured xml document can be displayed. The objects are organized into the following categories:1. Declaration, pagination & layout : This is used to define the basic layout of the page.
2. Block : When this type of formatting is used it creates paragraphs, block quotes etc.
3. Inline : On using this formatting technique it would create styles such as itlaics , colors and special characters inside a block.
4. Table : This is used for the creation and controlling of tables.
5. List : This type of formatting is used to control the lists of all types.
6. Links and multi : They are used to handle the style links and multimedia components.
7. Out-of-line : This formatting create and style the float areas.
8. Other : This is used as a ctach all for all the objects that dont fit in anywhere else.

Q23. What are the types of nodes in the Xpath data model? Explain briefly.
There are seven kinds of nodes in the Xpath data model:
1. Root node : This node is the root of the xml document and contains all the elements of the document.
2. Element node : For every element in a document there exists an element node that will in turn contain other elements within it.
3. Attribute node : Every element node has a set of associated attribute nodes.
4. Namespace node : Every element has a namespace node associated to it. Similar to attribute nodes the element nodes are parents to the namepsace nodes.
5. Processing instruction node : For every processing instruction in a document there exists a SOLARISTM Kernel – Solaris Internals and Performance FAQprocessing instructions node.
6. Comment node : For every comment contained in a document there is a comment node unless it is a part of the dtd.
7. Text node : All character data are stored in the text nodes. Every text node in itself contains at least one character.

Q24. In XML how can the user create code which contains content that would be ignored by the parser?
Generally an xml parser would parse through all the text in an XML document. When the parser parses through an xml element all the text between the tags is also parsed. The parser has been programmed to do so as a tag may contain more tags inside it. In case the user wants to specify any content that he does not want the parser to parse he can use the property of CDATA. Everything that a user specifies within a cdata section would be ignored by the parser.

Q25. Explain the used of the xml prolog section.
The xml prolog of a xml document is the beginning of an xml document. It consists of the information about the xml document and can be used by both the users and computers to know about the document. The prolog to an xml schema must contain:XML declaration : The xml declaration is used to specify the version of xml used to write it and to declare that the document is an xml.For Example:<?xml version=”1.0” encoding=”UTF-8”?>The xml element or root declaration : It defined the root element within which all the other xml elements / tags used are contained. In case of schemas it consists of an xmlns ( xml namespace) attribute that is used to define the namespace for the schema.For Example:<xsd:schema xmlns: xsd=”http://www.abc.org/2001/XMLSchema”>

Summary
Review Date
Reviewed Item
These XML Interview Questions and Answers are very useful..
Author Rating
51star1star1star1star1star