Breaking News

Editors Picks

Tuesday, June 22, 2010

XML interview question

What is XML?
XML stands for EXtensible Markup Language. XML is a markup language much like HTML. XML was designed to carry data, not to display data. XML tags are not predefined. You must define your own tags. XML is designed to be self-descriptive.
What is the version information in XML?
“Version” tag shows which version of XML is used.
What is ROOT element in XML?
Root element is the top most elements for a XML.
If XML does not have closing tag will it work?
No, every tag in XML, which is opened, should have a closing tag. For instance in the top if I remove tag that XML will not be understood by lot of application.
Is XML case sensitive?
Yes, they are case sensitive.
What is the difference between XML and HTML?
XML describes data while HTML describes how the data should be displayed. Therefore, HTML is about displaying information while XML is about describing information.
Is XML meant to replace HTML?
No, they both go together one is for describing data while other is for displaying data.
Can you explain why your project needed XML?
Remember XML was meant to exchange data between two entities as you can define your userfriendly tags with ease. In real world scenarios, XML is meant to exchange data. For instance,you have two applications who want to exchange information. However, because they work in two complete opposite technologies it is difficult to do it technically. For instance, one application is made in JAVA and the other in .NET. However, both languages understand XML so one of the applications will spit XML file, which will be consumed and parsed by other applications You can give a scenario of two applications, which are working separately and how you chose XML as the data transport medium.
What is DTD (Document Type Definition)?
It defines how your XML should structure. For instance in the above XML we want to make it compulsory to provide “qty” and “total cost”, also that these two elements can only contain numeric. Therefore, you can define the DTD document and use that DTD document with in that XML.
What is well formed XML?
If a XML document is confirming to XML rules (all tags started are closed, there is a root element etc) then it is a well-formed XML.







               
What is a valid XML?
If XML is confirming to DTD rules then it is a valid XML.
What is CDATA section in XML?
All data is normally parsed in XML but if you want to exclude some elements, you will need to put those elements in CDATA.
What is XSL?
XSL (the extensible Style sheet Language) is used to transform XML document to some other document. Therefore, its transformation document which can convert XML to some other document. For instance, you can apply XSL to XML and convert it to HTML document or probably CSV files.
Which are the namespaces in .NET used for XML?
“System.xml.dll” is the actual physical file, which has all XML implementation. Below are the commonly used namespaces:-

System.Xml
System.Xml.Schema
System.Xml.XPath
System.Xml.Xsl
What are the standard ways of parsing XML document?
XML parser sits in between the XML document and the application who want to use the XML document. Parser exposes set of well-defined interfaces, which can be used by the application for adding, modifying, and deleting the XML document contents. Now whatever interfaces XML parser exposes should be standard or else that would lead to different vendors preparing there own custom way of interacting with XML document.

There are two standard specifications, which are very common and should be followed by a XML parser:-

DOM: - Document Object Model.
DOM is a W3C recommended way for treating XML documents. In DOM, we load entire XML document into memory and allows us to manipulate the structure and data of XML document.

SAX: - Simple API for XML.
SAX is event driven way for processing XML documents. In DOM, we load the whole XML document in to memory and then application manipulates the XML document. However, this is not always the best way to process large XML documents, which have huge data elements. For instance, you only want one element from the whole XML document or you only want to see if the XML is proper which means loading the whole XML in memory will be quiet resource intensive. SAX parsers parse the XML document sequentially and emit events like start and end of the document, elements, text content etc. Therefore, applications who are interested in processing these events can register implementations of callback interfaces. SAX parser then only sends those event messages, which the application has demanded.

In What scenarios will you use a DOM parser and SAX parser?
If you do not need all the data from the XML file then SAX approach is much preferred than DOM as DOM can be quiet memory intensive. In short, if you need large portion of the XML document its better to have DOM.

With SAX parser, you have to write more code than DOM.

If you want to write the XML in to a file, DOM is the efficient way to do it.

Some time you only need to validate the XML structure and do not want to retrieve any Data for those instances SAX is the right approach.
How was XML handled during COM times?
During COM, it was done by using MSXML 4.0. So old languages like VB6, VC++ used MSXML 4.0, which was shipped with SP1 (Service Pack 1).
What is the main difference between MSML and .NET Framework XML classes?
MSXML supports XMLDOM and SAX parsers while .NET framework XML classes support XML DOM and XML readers and writers.

MSXML supports asynchronous loading and validation while parsing. For instance, you can send synchronous and asynchronous calls to a remote URL. However, as such there is not direct support of synchronous and asynchronous calls in .NET framework XML. However, it can be achieved by using “System.Net” namespaces.
What are the core functionalities in XML .NET framework? Can you explain in detail those functionalities?

The XML API for the .NET Framework comprises the following set of functionalities:

XML readers
With XML readers, the client application gets reference to instance of reader class. Reader class allows you to scroll forward through the contents like moving from node to node or element to element. You can compare it with the “SqlDataReader” object in ADO.NET, which is forward only. In short, XML reader allows you to browse through the XML document.

XML writers
Using XML writers, you can store the XML contents to any other storage media. For instance,you want to store the whole in memory XML to a physical file or any other media.

XML document classes
XML documents provides a in memory representation for the data in an XMLDOM structure as defined by W3C. It also supports browsing and editing of the document. Therefore, it gives you a complete memory tree structure representation of your XML document.
What is XSLT?
XSLT is a rule-based language used to transform XML documents in to other file formats. XSLT are nothing but generic transformation rules, which can be applied to transform XML document to HTML, CS, Rich text etc.








               
Define XPATH?
It is an XML query language to select specific parts of an XML document. Using XPATH, you can address or filter elements and text in a XML document.
What is the concept of XPOINTER?
XPOINTER is used to locate data within XML document. XPOINTER can point to a particular portion of a XML document, for instance
address.xml#xpointer (/descendant::streetnumber[@id=9])
So the above XPOINTER points street number=9 in “address.xml”.
What is an XMLReader Class?
It is an abstract class available from System.XML namespace. XML reader works on a read-only stream browsing from one node to other in a forward direction. It maintains only a pointer to the current node but has no idea of the previous and the next node. You cannot modify the XML document, you can only move forward.
What is XMLTextReader?

The “XmlTextReader” class helps to provide fast access to streams of XML data in a forwardonly and read-only manner. It also checks if the XML is well formed. However, XMLTextReader does not validate against a schema or DTD for that you will need “XmlNodeReader” or “XmlValidatingReader” class.

Instance of “XmlTextReader” can be created in number of ways. For example if you want to load file from a disk you can use the below snippets.
XmlTextReader reader = new XmlTextReader (filename);
To loop through all the nodes you need to call the “read ()” method of the “XmlTextreader” object. “read()” method returns “true” if there are records in the XML document or else it returns “false”.

//Open the stream
XmlTextReader reader = new XmlTextReader (file);
While (reader. Read())
{
// your logic goes here
String pdata = reader. Value
}
// Close the stream
Reader. Close ();

To read the content of the current node on which the reader object is you use the “value” property. As shown in the above code “pdata” gets the value from the XML using “reader.Value”.
How do we access attributes using “XmlReader”?
Below snippets shows the way to access attributes. First in order to check whether there any attributes present in the current node you can use “HasAttributes” function and use the “MoveToNextAttribute” method to move forward in attribute. In case you want to move to the next element use “MoveToElement ()”.

if (reader.HasAttributes)
{
while(reader.MoveToNextAttribute())
{
// your logic goes here
string pdata = reader.Value
}
}
reader.MoveToElement();
What does XmlValidatingReader class do?
XmlTextReader class does not validate the contents of an XML source against a schema. The correctness of XML documents can be measured by two things is the document well formed and is it valid. Well-formed means that the overall syntax is correct. Validation is much deeper which means is the XML document is proper w.r.t schema defined.

Therefore, the XmlTextReader only checks if the syntax is correct but does not do validation. There is where XmlValidatingReader class comes in to picture. Therefore, this again comes at a price as XmlValidatingReader have to check for DTD and Schema’s that’s the reason they are slower compared to XmlTextReader.







               
   
   
   

Read more ...

Contact Us

Name

Email *

Message *