Definition XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to carry data, to transport and store data, not to display data XML tags are not predefined. You must define your own tags XML is designed to be self-descriptiveThe best description of XML is: “XML is asoftware and hardware-independent tool forcarrying information”.
XML & HTML XML is not a replacement for HTML. XML and HTML were designed with different goals: ◦ XML was designed to transport and store data, with focus on what data is ◦ HTML was designed to display data, with focus on how data looks ◦ HTML is about displaying information, while XML is about carrying information.
First Example<note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Dont forget me this weekend!</body></note> The note above is quite self-descriptive. It has sender and receiver information, it also has a heading and a message body.
XML Tags The tags in the example above (like <to> and <from>) are not defined in any XML standard. These tags are "invented" by the author of the XML document. That is because the XML language has no predefined tags. The tags used in HTML are predefined. HTML documents can only use tags defined in the HTML standard (like <p>, <h1>, etc.). XML allows the author to define his/her own tags and his/her own document structure.
XML Main FeaturesXML Simplifies Data TransportExchanging data as XML greatly reduces thiscomplexity, since the data can be read by differentincompatible applications. JAVA PHP DOC. XML .NET
XML Separates Data from HTMLIf you need to display dynamic data in your HTMLdocument, it will take a lot of work to edit the HTML each timethe data changes.With XML, data can be stored in separate XML files. This wayyou can concentrate on using HTML/CSS for display andlayout, and be sure that changes in the underlying data willnot require any changes to the HTML..
XML Makes Your Data More AvailableDifferent applications can access your data, not only inHTML pages, but also from XML data sources.With XML, your data can be available to all kinds of "readingmachines" (Handheld computers, voice machines, newsfeeds, etc), and make it more available for blind people, orpeople with other disabilities.
XML Simplifies Platform ChangesXML data is stored in text format. This makes iteasier to expand or upgrade to new operatingsystems, new applications, or newbrowsers, without losing data.XML Simplifies Data SharingIn the real world, computer systems anddatabases contain data in incompatible formats.
XML Tree XML documents form a tree structure that starts at "the root" and branches to "the leaves".
Tree Structure XML documents must contain a root element. This element is "the parent" of all other elements. The elements in an XML document form a document tree. The tree starts at the root and branches to the lowest level of the tree. All elements can have sub elements (child elements). <root> <child> <subchild attribute=”value”>.....</subchild> </child> </root>
XML Syntax Rules All XML Elements Must Have a Closing Tag. XML Tags are Case Sensitive. XML Elements Must be Properly Nested. XML Documents Must Have a Root Element. XML Attribute Values Must be Quoted.<root> <child> <subchild attribute=”value”>value #1</subchild> </child></root>
XML Elements An XML element is everything from (including) the elements start tag to (including) the elements end tag. An element can contain: ◦ other elements ◦ text ◦ attributes ◦ or a mix of all of the above...
XML Naming Rules XML elements must follow these naming rules: ◦ Names can contain letters, numbers, and other characters ◦ Names cannot start with a number or punctuation character ◦ Names cannot start with the letters xml (or XML, or Xml, etc) ◦ Names cannot contain spaces ◦ Any name can be used, no words are reserved
XML Elements are Extensible• XML elements can be extended to carry more information. <note> <to>Tove</to> <from>Jani</from> <body>Dont forget me this weekend!</body> </note> <note> <date>2008-01-10</date> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Dont forget me this weekend!</body> </note>
XML Attributes XML elements can have attributes, just like HTML. Attributes provide additional information about an element. In HTML, attributes provide additional information about elements: <img src="computer.gif"> <a href="demo.asp"> In the example below, the file type is irrelevant to the data, but can be important to the software that wants to manipulate the element: <file type="gif">computer.gif</file>
XML Attributes Must beQuoted Either single or double quotes can be used. For a persons sex, the person element can be written like this: <person sex="female"> or like this: <person sex=female> If the attribute value itself contains double quotes you can use single quotes, like in this example: <gangster name=George "Shotgun" Ziegler> or you can use character entities: <gangster name="George " Shotgun" Ziegler">
XML Elements vs. Attributes<person sex="female"> Attribute <firstname>Anna</firstname> <lastname>Smith</lastname></person><person> <sex>female</sex> Element <firstname>Anna</firstname> <lastname>Smith</lastname></person> *Authors recommends use as Elements
Using XML Attributes Some of the problems with using attributes are: ◦ attributes cannot contain multiple values (elements can) ◦ attributes cannot contain tree structures (elements can) ◦ attributes are not easily expandable (for future changes) Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.Example using only attributes: <note day="10" month="01" year="2008" to="Tove" from="Jani" heading="Reminder" body="Dont forget me this weekend!“> </note>
XML Validation XML with correct syntax is "Well Formed" XML. • A "Well Formed" XML document has correct XML syntax. • Use the correct syntax rules. • XML documents must have a root element• XML elements must have a closing tag• XML tags are case sensitive• XML elements must be properly nested• XML attribute values must be quoted
XML validated against a DTD is "Valid" XML.• A "Valid" XML document is a "Well Formed" XML document, which also conforms to the rules of a Document Type Definition (DTD)
The purpose of a DTD is to define the structure of an XML document. It defines the structure with a list of legal elements: <!DOCTYPE noteXML DTD [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> W3C supports an XML-based alternative to DTD: <xs:element name="note">XML <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/>Schema <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>
Viewing XML Files Raw XML files can be viewed in all major browsers. If an erroneous XML file is opened, the browser will report the error. The XML document will be displayed with color-coded root and child elements. A plus (+) or minus sign (-) to the left of the elements can be clicked to expand or collapse the
Displaying XML with CSS With CSS (Cascading Style Sheets) you can add display information to an XML document. It is possible to use CSS to format an XML document. Let’s see an example of how to use a CSS style sheet to format an XML document.