Sunteți pe pagina 1din 5

Introduction To XML As we know that HTML and HTTP are the most commonly tools used for the

communication on Internet, XML (extensive markup language, A markup language is a set of code which is used to display the content, content may be collection of words or anything) is also going to be big thing for communication on internet in both ways(machine to Machine or human). In case of XML you create your own tags so that anyone can easily what is doing this XML code. E.g. <? XML Version 1.0?/> <Statement>Hi, This is Statement Tag</Statement> In this code first line is explaining the XML version used and Second line showing the user made a statement tag.

DTD: Document type Definition The purpose of a DTD (Document Type Definition) is to define the legal building blocks of an XML document. A DTD defines the document structure with a list of legal elements and attributes. Why we are using XML for data communication: Platform Independent XML separates the data from HTML Data sharing is much easier Simplifies the data sharing Makes data more available

XML Syntax XML syntaxes must has a closing tag. XML syntaxes are Case Sensitive. Some special character like <,>,,,& cant be place inside the syntaxes to use the these characters we use some special codes for it. &lt= less than &gt= greater than &amp=ampersand &apos=apostrophe &quot=quotation mark XML attribute values must be quoted. Like <Date =12/03/12></Date>

Comments in XML

<-- This is a comment -- >

XML Elements An element is everything inside the XML start tag to end tag. E.G. <bookstore> <bookname>ABC</bookname> <author>XYZ</author> <ISBN>123</ISBN> </bookstore>

Valid XML Document A valid XML Document is a collection of elements which is well formed and also confirms the DTD rules.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE note SYSTEM "Note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Above written code is a valid xml content because it is according to rule of DTD and reference to a external DTD file which written below. <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]>

W3C supports a xml based schema which is alternative to the DTD.


<xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element>

XML Errors Will Stop You Errors in XML documents will stop your XML applications. The W3C XML specification states that a program should stop processing an XML document if it finds an error. The reason is that XML software should be small, fast, and compatible. HTML browsers will display documents with errors (like missing end tags). HTML browsers are big and incompatible because they have a lot of unnecessary code to deal with (and display) HTML errors.

XML Namespace Some time when we work on large amount of data we cant give the each element different name in this case use of namespace is very important e.g.
<table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table>

If these XML fragments were added together, there would be a name conflict. Both contain a <table> element, but the elements have different content and meaning. So using namespace convention
<root> <h:table xmlns:h="http://www.w3.org/TR/html4/"> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f="http://www.w3schools.com/furniture"> <f:name>African Coffee Table</f:name>

<f:width>80</f:width> <f:length>120</f:length> </f:table> </root>

XML Encoding
<?xml version="1.0" encoding="windows-1252"?>

Here the xml file is saved as after encoding rather than saving it in ascii characters. Real Life Example of XML Data
<?xml version="1.0" encoding="ISO-8859-1"?> <nitf> <head> <title>Colombia Earthquake</title> </head> <body> <headline> <hl1>143 Dead in Colombia Earthquake</hl1> </headline> <byline> <bytag>By Jared Kotler, Associated Press Writer</bytag> </byline> <dateline> <location>Bogota, Colombia</location> <date>Monday January 25 1999 7:28 ET</date> </dateline> </body> </nitf>

S-ar putea să vă placă și