130 likes | 239 Vues
This document provides an overview of XML (Extensible Markup Language), highlighting its purpose in data transportation and storage. Unlike HTML, which is used for displaying content, XML allows users to define their own tags and structure data in a self-descriptive manner. It is platform-independent, robust, and allows for data sharing and manipulation across applications. The guide covers XML syntax, naming rules, attributes, validation, and how to create an XML file, making it essential for developers and information technologists.
E N D
INF201 Fall2010Intro. to Info. Technologies Department of Informatics University at Albany – SUNY Original Source: w3schools.com Prepared by Xiao Liang, fall 2010 Adapted from Choi, Spring2009
WhatisXML • XML stands for EXtensible Markup Language • XML is a markup language much like HTML • XML was designed to carry data, not to display data • XML tags are not predefined. You must define your own tags • XML is designed to be self‐descriptive • XML is a W3C Recommendation
XML vs. HTML • XML was designed to transport and store data. • You design your own tags • HTML was designed to display data. • Tags are predefined. • XML does not DO anything. XML was created to structure, store, and transport information.
WhyXML? • XML iscomputerunderstandable,andcomputerusable • XML provideastandardway,avoidingerrors • XML provides a robust and durable format for information storage and transmission. Robust because it is based on a proven standard, and can thus be tested and verified; durable (persistent) because it uses plain-text file formats which will outlast proprietary binary ones. • XML provides a common syntax for messaging systems for the exchange of information between applications • XML is free. Not just free of charge (free as in beer) but free of legal encumbrances (free as in speech). • XML information can be manipulated programmatically (under machine control), so XML documents can be pieced together from disparate sources, or taken apart and re-used in different ways. They can be converted into any other format with no loss of information. • XML lets you separate form (appearance) from content. Forreference:http://xml.silmaril.ie/basics/whyxml/
How Can XML be Used? • XML Separates Data from HTML • XML Simplifies Data Sharing and Data Transport • XML data is stored in plain text format. This provides a software‐and hardware‐independent way of storing data. • Platform independent • A lot of new Internet languages are created with XML
XMLexample <?xml version="1.0"?> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
XMLSyntax • XML declaration<?xml version="1.0"?> • Root element (Required)<note> • Child element(<to>,<from>,<heading>,<body>) • All XML Elements Must Have a Closing Tag • XML Tags are Case Sensitive<Letter> is different from the tag <letter> • XML Elements Must be Properly Nested<to><title>This is incorrect</to></title>notright • XML Attribute Values Must be Quoted <note date="09/29/2009">
XMLdocumentstructure <root> <child> <subchild>.....</subchild> </child></root>
XML NamingRules • XML 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
XML Attributes • Attributes often provide information that is not a part of the data.<file type="gif">computer.gif</file> • It is NOT recommended to use attributesattributes cannot contain multiple values (elements can) • attributes cannot contain tree structures (elements can) • attributes are not easily expandable (for future changes)
XML Validation • XML with correct syntax is "Well Formed" XML. • XML validated against a DTDis "Valid" XML. • XML SchemaXML‐based alternative to DTD • W3schools.com XML Validator
XML Style • DisplayingXML with CSS HTML is designed for content being sent to a browser. XML can be converted to HTML and read by browsers • Displaying XML with XSLT eXtensibleStylesheet Language Transformations To transform XML to HTML
Howtocreatexmlfile? • Eitherusenotepadordreamweaver • DonotforgetputXML declaration<?xml version="1.0"?> • Saveasfilename.xml