<?xml version="1.0"?>
<note>
<to>zain</to>
<from>maham</from>
<heading>massege</heading>
<body>Don't forget me today!</body>
</note>
XML Element Code
<bookstore>
<book category="boys">
<title>name</title>
<author>zain</author>
<year>2010</year>
<price>21.19</price>
</book>
<book category="internet">
<title>Learning language</title>
<author>zain</author>
<year>2010</year>
<price>35.91</price>
</book>
</bookstore>
Attributes code
<img src="computer.gif">
<a href="demo.asp">
<file type="gif">computer.gif</file>
<person sex="female">
<gangster name='George "Shotgun" Ziegler'>
Validation Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE note SYSTEM "Note.dtd">
<note>
<to>zain</to>
<from>maham</from>
<heading>text</heading>
<body>Don't forget me today!</body>
</note>
Validator Code
<?xml version="1.0" ?>
<note>
<to>zain</to>
<from>maham</Ffrom>
<heading>textr</heading>
<body>Don't forget me today!</body>
</note>
XML To Use CSS
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
<CATALOG>
<CD>
<TITLE>name</TITLE>
<ARTIST>zain</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Orcale</COMPANY>
<PRICE>15.40</PRICE>
<YEAR>1999</YEAR>
</CD>
<CD>
<TITLE>name</TITLE>
<ARTIST>zain</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Microsoft</COMPANY>
<PRICE>10.10</PRICE>
<YEAR>2000</YEAR>
</CD>
.
.
</CATALOG>
HTTP Code
xmlhttp=new XMLHttpRequest();
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
Parser Code
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","books.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
Dom Code
<html>
<body>
<h1>classcomputercode</h1>
<div>
<b>To:</b> <span id="to"></span><br />
<b>From:</b> <span id="from"></span><br />
<b>Message:</b> <span id="message"></span>
</div>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","note.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.getElementById("to").innerHTML=
xmlDoc.getElementsByTagName("to")[0].childNodes[0].nodeValue;
document.getElementById("from").innerHTML=
xmlDoc.getElementsByTagName("from")[0].childNodes[0].nodeValue;
document.getElementById("message").innerHTML=
xmlDoc.getElementsByTagName("body")[0].childNodes[0].nodeValue;
</script>
XML To HTML Code
<html>
<body>
<script type="text/javascript">
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","cd_catalog.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
document.write("<table border='1'>");
var x=xmlDoc.getElementsByTagName("CD");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</body>
</html>
Application Code
x=xmlDoc.getElementsByTagName("CD");
i=0;
function displayCD()
{
artist=(x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue);
title=(x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue);
year=(x[i].getElementsByTagName("YEAR")[0].childNodes[0].nodeValue);
txt="Artist: " + artist + "<br />Title: " + title + "<br />Year: "+ year;
document.getElementById("showCD").innerHTML=txt;
}
Namespace Code
<table>
<name>pakistani boys</name>
<width>50</width>
<length>100</length>
</table>
Encoding Code
<?xml version="1.0"?>
<note>
<from>zain</from>
<to>maham</to>
<message>Norwegian: æøå. French: êèé</message>
</note>
Servic Code
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<from>zain</from>
<to>maham</to>
<message>Remember me today</message>
</note>
Dom Advance Code
txt=xmlDoc.getElementsByTagName("title")[0].getAttribute("ang");x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
or
x.nodeValue="Easy Cooking";
Don't Code
<html>
<body>
<xml id="cdcat" src="cd_catalog.xml"></xml>
<table border="1" datasrc="#cdcat">
<tr>
<td><span datafld="ARTIST"></span></td>
<td><span datafld="TITLE"></span></td>
</tr>
</table>
</body>
</html>
E4X Code
var employees=
<employees>
<person>
<name>abbas</name>
<age>28</age>
</person>
<person>
<name>zain</name>
<age>23</age>
</person>
</employees>;
document.write(employees.person.(name == "Tove").age);