- Why Study XML?
- It is important to have a good understanding of XML.
- What is XML?
- Xml stands for extensible markup language.
- Xml designed to store and transport data.
- XML doesn’t do anything. It is just information wrapped in tags.
- Difference between XML and HTML:
- XML was designed to carry data – with focus on what data is and HTML was designed to display data with focus on how data looks.
- XML tags are not predefined like HTML tags are:
- XML language has no predefined tags.
- With XML, the author must define both the tags and the document structure.
- XML Simplifies Things like:-
- Data Sharing:-
- Exchanging data between incompatible systems is a time-consuming task for web developers. Large amounts of data must be converted, and incompatible data is often lost.
- XML stores data in plain text format. This provides a software- and hardware-independent way of sharing data.
- Data transport:-
- XML stores data in plain text format. This provides a software- and hardware-independent way of storing and transporting data.
- Platform changes:-
- With XML, it is easier to expand or upgrade to new operating systems, applications, or new browsers, without losing data.
- Data availability :-
- XML also makes it available to all kinds of reading machines like computers, voice machines, peoples, news feeds, etc.
- Data Sharing:-
- XML Separates Data From Presentation:-
- XML doesn’t know how the data should be displayed.
- Same XML data can be used in many different presentation scenarios.
- XML Syntax Rules:-
- XML Prolog:-
-
<?xml version= "1.0" encoding="UTF-8"?>
- XML prolog is optional.
XML Rules:-
- All XML elements must have a closing tag.
- XML elements must be properly nested.
- XML tags are case sensitive.
- XML elements must start with a letter or underscore but cannot start with letters xml.
- XML elements can contain letters, digits, underscores, hyphens, and periods but cannot contain spaces.
- XML attributes values must always be quoted ( either single or double quotes).
- There are 5 pre-defined entity references in XML.
Entity Char < < > > & & ' ' " " - Comments in XML
- <!—Comments -->
- Two dashes (--) in the middle of a comment are not allowed.
- XML stores a new line as LF.
- White space is preserved in XML.
- <TAG> Hello world </TAG>
- Self-closing tag are allowed in empty elements.
- <element /> OR <element>...</element>
How To Handle Name Conflicts:-
- If multiple XML fragments are added together, there would be a name conflict.
- Name conflicts in xml can be easily avoided by using a name prefix.
- <h:name>…</h:name> and <p:name>…</p:name>
XML Namespaces:-
- A Namespace is a set of unique names. Namespace is a mechanism by which element and attribute name can be assigned to a group.
- When using prefixes in XML, a namespace for the prefix must be defined.
- It is defined by xmlns attribute in the start tag of an element.
- Namespace declaration has the following syntax:
<s:tag xmlns:s="http://fit-coder.blogspot.com/p/names"> <s:name> …</s:name> </s:tag>
XML Parser:-
Parsing a Text String :-
-
<html> <head> <script> var str, parser, doc; str ="<store><chips>"+ //Text string is defined "<name> Haldiram </name>"+ "<flavor> chili </flavor>"+ "</chips></store>"; //DOMParser() is an class to create new parser object. parser = new DOMParser(); //parser create a new XML DOM object using the str string. doc = parser.parseFromString(str, “text / xml"); document.getElementById(“demo").innerHTML = doc.getElementsByTagName(“name")[0].childNodes[0].nodeValue; </script> </head> <body> <h1 id="demo"></h1> </body> </html>
If you want to read the Question that are asked in interview, You can download the app InterQue,that Have many questions.

Comments
Post a Comment