Google News
logo
XML Interview Questions
JSON Pro :
 
* Simple syntax, which results in less "markup" overhead compared to XML.
* Easy to use with JavaScript as the markup is a subset of JS object literal notation and has the same basic data types as JavaScript.
* JSON Schema for description and datatype and structure validation
* JsonPath for extracting information in deeply nested structures

JSON Con :
 
* Simple syntax, only a handful of different data types are supported.
* No support for comments.
 
XML Pro :
 
* Generalized markup; it is possible to create "dialects" for any kind of purpose
* XML deals remarkably well with the full richness of unstructured data CDATA
* XML Schema for datatype, structure validation. Makes it also possible to create new datatypes
* XSLT for transformation into different output formats
* XPath/XQuery for extracting information in deeply nested structures
* built in support for namespaces
 
XML Con :
 
* Relatively wordy compared to JSON (results in more data for the same amount of information).
* XML presents a 21% overhead over JSON
* Requires some reasonable more time to compress.
A CDATA section is "a section of element content that is marked for the parser to interpret as only character data, not markup." The data contained therein will not be parsed as XML, and as such does not need to be valid XML or can contain elements that may appear to be XML but are not.
<![CDATA[
Within this Character Data block I can
use double dashes as much as I want (along with <, &, ', and ")
*and* %MyParamEntity; will be expanded to the text
"Has been expanded" ... however, I can't use
the CEND sequence. If I need to use CEND I must escape one of the
brackets or the greater-than sign using concatenated CDATA sections.
]]>
(Or)
<description>An example of escaped CENDs</description>
<!-- This text contains a CEND ]]> -->
<!-- In this first case we put the ]] at the end of the first CDATA block
     and the > in the second CDATA block -->
<data><![CDATA[This text contains a CEND ]]]]><![CDATA[>]]></data>
<!-- In this second case we put a ] at the end of the first CDATA block
     and the ]> in the second CDATA block -->
<alternative><![CDATA[This text contains a CEND ]]]><![CDATA[]>]]></alternative>
var xhttp= newXML Httprequest();
Xhttp.onreadystatechange=function();
{ If this.readystate==4&& this.status==200)
        { Action to be performed when document is ready;
Document.getelementbyID(“Demo”)
Innerhtml=xhttp.responseText;}};
Basically, every element (or attribute) in XML belongs to a namespace, a way of "qualifying" the name of the element.
 
Imagine you and I both invent our own XML. You invent XML to describe people, I invent mine to describe cities. Both of us include an element called name. Yours refers to the person’s name, and mine to the city name—OK, it’s a little bit contrived.
<person>
    <name>Ramana</name>
    <age>31</age>
    <homecity>
        <name>India</name>
        <lat>123.024</lat>
        <long>120.010</long>
    </homecity>
</person>
If our two XMLs were combined into a single document, how would we tell the two names apart? As you can see above, there are two name elements, but they both have different meanings.
 
The answer is that you and I would both assign a namespace to our XML, which we would make unique:
<personxml:person xmlns:personxml="https://www.freetimelearning.com/xml/person"
                  xmlns:cityxml="http://www.freetimelearn.com/xml/cities">
    <personxml:name>Ramana</personxml:name>
    <personxml:age>31</personxml:age>
    <cityxml:homecity>
        <cityxml:name>India</cityxml:name>
        <cityxml:lat>123.024</cityxml:lat>
        <cityxml:long>120.010</cityxml:long>
    </cityxml:homecity>
</personxml:person>
Now we’ve fully qualified our XML, there is no ambiguity as to what each name element means. All of the tags that start with personxml: are tags belonging to your XML, all the ones that start with cityxml: are mine.
Processing Instruction is defined in the XML standard, XML 1.0 Recommendation. The definition says: "Processing instructions (PIs) allow documents to contain instructions for applications… PIs are not part of the document's character data, but MUST be passed through to the application."
 
Following is the syntax of PI :
<?target instructions?>
And some examples :
<?display table-view?>
<?sort alpha-ascending?>
<?textinfo whitespace is allowed ?>
<?elementnames <fred>, <bert>, <harry> ?>
In the real world PIs are seldom used with a few common exceptions. The PI is the official method for an XML document to link to a stylesheet, and Microsoft uses PIs in MS Office 2003 to make it easy for MS Word and MS Excel documents to be identified when saved as XML :
<?xml-stylesheet href="style.css" type="text/css"?>
XML data binding refers to the reading and writing of XML data using a programming language. XML data binding usually occurs using a class library (like C++, Java ), specifically for the given XML data format.
 
With XML data binding, applications can directly access the required data with the XML file’s created APIs instead of relying on the Document Object Model (DOM) to retrieve the data from the XML file.
An XML parser is a software library that provides an interface for client applications to work with XML documents.
 
Working of XML Parser : XML Document which undergoes XML parser (usually the API part), and then this API is used in Client Applications.
 
There are two types of XML parser :
 
1.DOM 
2.SAX
The distinction between well-formed and valid XML is straightforward : Valid XML is associated with a DTD and has been validated against all of the DTD's rules in addition to being well-formed. However, simply well-formed XML is not necessarily valid, though it may be.
The element within the element is referred to as XML nested elements. The structure begins with a root element, which is followed by another element. The most outer element is the root element. All of the other elements mentioned can have inner elements within the root element.
Step 1 : Review the structure of your pages.
 
The first thing you need to do is look at your website’s existing content and see how everything is structured.
 
Step 2 : Code your URLs
 
Format each URL with XML tags for each page, which you wish the search engine to crawl for search results.
 
Step 3 : Validate the code.
 
Validate code with tools like XML SiteMap Validator
 
Step 4 : Add your sitemap to the root and robots.txt
 
Locate the root folder of your website and add the sitemap file to this folder and also to robots.txt
 
Step 5 : Submit your sitemap.
 
Submit your website to Google Search Console.

Example : 
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.freetimelearning.com/</loc>
    <lastmod>2017-10-04T22:37:13+00:00</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>
</urlset>