20 XML Interview Questions and Answers - Freshers, Experienced

Dear Readers, Welcome to XML interview questions with answers and explanation. These 20 solved XML questions will help you prepare for technical interviews and online selection tests conducted during campus placement for freshers and job interviews for professionals.

After reading these tricky XML questions, you can easily attempt the objective type and multiple choice type questions on this topic.

How can name conflicts be avoided in XML?

XML allows the user to create their own tags this can lead to conflicts if an attempt is made to mix two different XML documents from different XML applications. In order to avoid this XML uses the concept of namespaces. Which simply uses a prefix to differentiate between two similarly named tags.

For Example:
<table>
<tr>
<td>boy</td>
<td>girl</td>
</tr>
</table>
<table>
<name>Coffee Table</name>
<width>180</width>
<length>320</length>
</table>

In the above case if both the xml code was to be clubbed together there would be a naming conflict as both the tags of name consists of different content and meaning. In order to avoid this the user simply has to use namespaces.
ie the above code can be re written as:
<a:table>
<a:tr>
<a:td>boy<a:/td>
<a:td>girl<a:/td>
</a:tr>
</a:table>
<b:table>
<b:name>Coffee Table</b:name>
<b:width>180</b:width>
<b:length>320</b:length>
</b:table>

In this way no conflicts occur.

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.

The syntax for CDATA section:
<![CDATA[" and ends with "]]>

Some of the restrictions of the cdata section are:
- A cdata section cannot contain the string “]]>”.
- CDATA section nesting is not allowed.

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.

Write a code for XML news?

The xml news is a specification that is used for the exchange of information and news. An example of an XML news document is as follows:
<?xml version="1.0" encoding="ISO-8859-1"?>
<nitf>
<head>
     <title>Natural Disaster</title>
</head>
<body>
<headline>
     <hl1>143 Dead in Natural Disaster</hl1>
</headline>
<byline>
     <bytag>By Bob Roy, News Line Press</bytag>
</byline>
<dateline>
     <location>Lonely Planet</location>
     <date>Monday January 12 2012 9:13 ET</date>
</dateline>
</body>
</nitf>

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.

What is E4X in reference to XML?

The E4X is a java script standard that is officially released by them. It extends the direct support of xml in java scripts. It allows the user to declare a xml variable in the same way an array is declared.

For Example:
var x = new XML()
var employees=
<employees>
<person>
     <name>Tove</name>
     <age>32</age>
</person>
<person>
     <name>Jani</name>
     <age>26</age>
</person>
</employees>;

document.write(employees.person.(name == "Tove").age);

The E4X on being used by the user greatly reduces the amount of code that has to be written to execute an operation.

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>

In the above code the id is used to identify different xml elements, this is also a form of metadata.

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.

What do you understand by SVG and SMIL? Give examples

The SVG and SMIL are xml languages that are specifically used for multimedia purposes.

1. SVG (scalable vector graphics) : This language enables the user to display 2 dimensional vector graphic images and animations from the xml code. It makes use of the vector mathematical formulas to render the content.
2. SMIL (synchronized multimedia integration language) : This language is used to integrate text , images and other media together for a presentation.
For Example : A simple svg example:
<svg xmlns="http://www.abc.org/2000/svg"
xmlns:xlink="http://www.abc.org/1999/xlink">
<rect x="10" y="10" height="100" width="100"
style="stroke:#ff0000; fill: #0000ff"/>
</svg>

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.

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”>

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>

What are the different scenarios under which an xml schema may be used?

The xml schema may be used in case the user wants to have the following requirements:

1. The xml schema can be used when the user requires the information to be included in the document is correct and in a consistent format.
2. It can be used when the user has to create a large set of xml documents with all the documents following a common structure.
3. When the document structure is to be shared with other users if an application is built and it follows a particular file structure.
4. Schema in xml are particularly helpful if the xml documents are going to contain a large amount of data. The schema gives the user the flexibility to define the structure according to his requirements.

How can child elements be specified upon using a sequence compositor?

When a sequence compositor is used the child elements can be specified in either of the two ways:

ref attribute : The ref attribute which will contain the value of the attribute which will be equal to the value of the name attribute in every child elements element declaration. This attribute should always refer to an actual element declaration.

For Example:
<xsd:complexType>
<xsd:sequence>
<xsd:element ref=”title”/>
</xsd:sequence>
</xsd:complexType>

name attribute : This attribute is used by specifying a value equal to the child elements name and with it the type attribute is specified as well. The type attribute would contain the user defined complex type.

For Example:
<xsd:element name=”book” type=”bookType”/>

Write the steps involved in the creation of a custom schema.

The main steps involved in the creation of a schema are as follows:

The creation of an XML prolog and schema element : During this process the user would define the information about the xml document and can contain annotataions for another uer or application to know more about the schema.
Adding namespace : Once the prolog and the schema element is defined the user can define the xmlns attribute to the schema.

For Example:
<?xml version=”1.0” encoding=”UTF-8”?>
<xsd:schema xmlns:xsd=”http://www.abc.org/2001/XMLSchema”>

Addition of all the element and attribute declarations created by the user. A snippet of the declarations is given below:
<xsd:complexType name=”bookType”>
<xsd:sequence>
<xsd:element ref=”title”/>
<xsd:element ref=”author”/>
<xsd:element ref=”publisher”/>
<xsd:element ref=”price”/>
<xsd:element ref=”isbn”/>
</xsd:sequence>

Saving the schema : once the user has entered all the declarations in the file the file can be saved using the .xsd extension.

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.

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.

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.

How can a xml file be created from a database?

To generate an xml database response from a server the user simply has to write the code and save it as an .asp file on the server.

The code:
<%
response.ContentType = "text/xml"
set conn=Server.CreateObject("ADODB.Connection")
conn.provider="Microsoft.Jet.OLEDB.4.0;"
conn.open server.mappath("/db/database.mdb")

sql="select fname,lname from tblGuestBook"
set rs=Conn.Execute(sql)

response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.write("<guestbook>")
while (not rs.EOF)
response.write("<guest>")
response.write("<fname>" & rs("fname") & "</fname>")
response.write("<lname>" & rs("lname") & "</lname>")
response.write("</guest>")
rs.MoveNext()
wend

rs.close()
conn.close()
response.write("</guestbook>")
%>

Briefly explain the XML spy 2005 multitool.

The xms spy is considered to be one of the best multi tools available around for xml. It knows how to deal with XSLT, XPath, XQuery, WSDL, SOAP etc.

The complete spy suite consists of the following products:

1. XMLSpy : This is a xml editor that allows the user to create, debug, validate and edit xml doucments in standard recognized way.
2. MaprForce : This is a visual data mapping tool that can be used by the user to change the data format from one form to another.
3. StyleVision : This application allows the user to create the XSLT and XSL:FO stylesheets which can be used to transform the xml documents. It can also be used to change the xml document into a HTML or PDF file.
XML - What is XML?
XML - XML, Extensible Markup Language, is an open, text based markup language that provides structural and semantic information to data......
XML document - List the rules to be followed by an XML document.
XML document - They must have a root tag, the document should be well formed : the tags should be properly closed, since XML is case sensitive, one should take care.....
XML DTD - Define DTD (Document Type definition).
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......
Post your comment
Discussion Board
XML interview questions and answers.
How do I create my own document type?
You can create your own document type by incorporating DTD or Schema. DTD and Schema is used with an XML editor that guide and control the construction of document. To create your own document type, analysis of class documents are required such as: reports, invoices, letter etc. Once the structure is set then the document type can be written according to your requirements.

How does XML handle metadata?
XML doesn’t have pre-defined elements as it is not an application, but an architecture which doesn’t verify the way the implementation of metadata being used. XML allows you to choose a suitable method to handle XML contents and its metadata information. XML also allows you to define your own markup language in which you can incorporate the extended hypertext features.

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>]]>

Rohit Sharma 12-11-2011
XML interview questions and answers.
How does XML handle white-space in my documents?
The white spaces are passed by the parser to the application. It includes the following elements: line-break, Tab, normal space. Parser then identifies the context in which the white spaces was found and send it to the application for further processing. Parser informs the application that, white space has occurred in element content. Application, after receiving the information decides which type of white space to discard and which to retain.

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).
Rohit Sharma 12-11-2011
XML interview questions and answers.
How can I use XML?
To use XML the requirement is to have a compatible browser that has the support of XML. You can use any browser which supports XML components or XML language. XML is just a file which gets created when you open any website on your browser. It saves your data information and allows the server and the client system to converse with each other. XML files are created with an extension of .xml.

How can I read an XML file?
You can use a web browser that supports XML format to open the XML file. If your file is a valid XML file then it will open in any XML supported web browser, if it is not a valid file then it will show an error and web browser won’t display the content of the file. Web browser will show the file in an unformatted way that may become hardly readable. If the file consists of CSS style sheet link, then browser will show the file in a formatted way which can be readable.

How do I control formatting and appearance?
One of the advantages of XML over HTML is that, it allows you to define your own tag set. To use the tags you have to create a style sheet, which is used to display the formatted text. The formatting and appearance will be implemented using the style sheet. The style sheet will be displayed on the browser in the format which you have specified.
Rohit Sharma 12-11-2011
XML interview questions and answers.
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.

What is Document Object Model? Why it is used?
Document Object Model also known as DOM, is an application programming interface that allows navigation through objects. The documents are treated as objects. DOM documents are either created by a parser or generated manually by users. DOM requires large portion of memory, as the entire document has to be loaded before any access to it, can be made.
Rohit Sharma 12-11-2011