XML interview questions and answers - freshers, experienced

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.
1 2

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