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:
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:
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"?>
<hl1>143 Dead in Natural Disaster</hl1>
<bytag>By Bob Roy, News Line Press</bytag>
<date>Monday January 12 2012 9:13 ET</date>
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()
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:
<body>Don't forget me this weekend!</body>
<body>I will not</body>
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:
- 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:
<rect x="10" y="10" height="100" width="100"
style="stroke:#ff0000; fill: #0000ff"/>
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.