IN Our XML Tutorial You Will Learn What XML IS AND THE DIFCERENCETWEEN XML AND HTML. You will Also Learn How To Start Using XML in your application.
Introduction TO XML
Xml Was Designed to Describe Data and To Focus on What Data IS. HTML WAS Designed to Display Data and To Focus on How Data Looks.
What You Should Already Know Before You Continue, You Should Have Some Basic Understanding of the Following:
WWW, HTML and the basics of building Web pages Web scripting languages like JavaScript or VBScript If you want to study these subjects first, before you start reading about XML, you can find the tutorials you need at W3Schools' Home Page.
What is xml?
XML stands for EXtensible Markup Language XML is a markup language much like HTML XML was designed to describe data XML tags are not predefined. You must define your own tags XML uses a Document Type Definition (DTD) or an XML Schema to describe the data XML With a dtd or XML Schema Is Designed to Be Self-Descriptive
The main difference between XML and HTML XML was designed to carry data XML is not a replacement for HTML.XML and HTML were designed with different goals:. XML was designed to describe data and to focus on what data is.HTML was designed to display Data and to focus on how data loocks. HTML IS About Displaying Information, While XML IS About Describing Information.
XML does not DO anything XML was not designed to DO anything. Maybe it is a little hard to understand, but XML does not DO anything. XML was created to structure, store and to send information. The following example is a note to Tove from Jani, Stored As XML:
XML is free and extensible XML tags are not predefined. You must "invent" your own tags. The tags used to mark up HTML documents and the structure of HTML documents are predefined. The author of HTML documents can only use tags that are defined in THE HTML Standard (Like
,
XML is a complement to HTML XML is not a replacement for HTML. It is important to understand that XML is not a replacement for HTML. In future Web development it is most likely that XML will be used to describe the data, while HTML will be Used to format and display The Same Data. My Best Description of XML IS THIS: XML IS A Cross-Platform, Software and Hardware Independent Tool For Transmitting Information.
XML in future Web development XML is going to be everywhere. We have been participating in XML development since its creation. It has been amazing to see how quickly the XML standard has been developed and how quickly a large number of software vendors have adopted the standard . We strongly believe that XML will be as important to the future of the Web as HTML has been to the foundation of the Web and that XML will be the most common tool for all data manipulation and data transmission.XML Joke Question: When should I Use xml? answer: when you need a buzzword in your resume.
How can XML BE USED?
IT Is Important To Understand That XML Was Designed To Store, Carry, And Exchange Data. Xml Was Not Designed to Display Data.
XML can Separate Data from HTML With XML, your data is stored outside your HTML. When HTML is used to display data, the data is stored inside your HTML. With XML, data can be stored in separate XML files. This way you can concentrate on using HTML for data layout and display, and be sure that changes in the underlying data will not require any changes to your HTML. XML data can also be stored inside HTML pages as "Data Islands". You can still concentrate on using HTML only For Formatting and Displaying the Data.
XML is used to Exchange Data With XML, data can be exchanged between incompatible systems. In the real world, computer systems and databases contain data in incompatible formats. One of the most time-consuming challenges for developers has been to exchange data between such systems Over the Internet. Converting The Data TO XML CAN GREATLY Reduce This Complexity and Create Data That Can Be Read by Many Different Types of Applications.
XML and B2B With XML, financial information can be exchanged over the Internet. Expect to see a lot about XML and B2B (Business To Business) in the near future. XML is going to be the main language for exchanging financial information between businesses over the Internet. A lot of interesting B2B applications are under development.XML can be used to Share Data With XML, plain text files can be used to share data. Since XML data is stored in plain text format, XML provides a software- and hardware- independent way of sharing data. This makes it much easier to create data that different applications can work with. It also makes it easier to expand or upgrade a system to new operating systems, servers, applications, and new browsers.
XML can be used to Store Data With XML, plain text files can be used to store data. XML can also be used to store data in files or in databases. Applications can be written to store and retrieve information from the store, and generic applications Can be used to display the data.
XML can make your Data more Useful With XML, your data is available to more users. Since XML is independent of hardware, software and application, you can make your data available to other than only standard HTML browsers. Other clients and applications can access your XML files as data sources, like they are accessing databases. your data can be made available to all kinds of "reading machines" (agents), and it is easier to make your data available for blind people, or people with other disabilities.
XML can be used to Create new Languages XML is the mother of WAP and WML. The Wireless Markup Language (WML), used to markup Internet applications for handheld devices like mobile phones, is written in XML. You can read more about WML in our WML tutorial.If Developers have Sense If they DO have sense, all future applications will exchange their data in XML. The future might give us word processors, spreadsheet applications and databases that can read each other's data in a pure text format, without any conversion Utilities in Between. We can Only Pray That Microsoft And All The Other Software Vendors Will Agree.
XML Syntax
The Syntax Rules of Xml Are Very Simple and Very Strict. The Rules Are Very Easy To Learn, And Very Easy To Use. Because of this, Creating Software That Can Read and Manipulate XML IS VERY EASY TO.
An Example XML Document XML Documents Use A Self-Describing and Simple Syntax.
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note> The first line in the document - the XML declaration - defines the XML version and the character encoding used in the document In this case the document conforms to the 1.0 specification of XML and uses the ISO-8859-1 (Latin. -1 / west european) Character set. The next line describes the root element of the document (like it is saying: "this document is a note":
Note> Can You Detect from this Example That The XML Document Contains a Note to Tove from Jani? Don't you agree That XML IS PRETTY SELF-Descriptive?
All XML Elements Must Have A Closing Tag with XML, IT ILLEGAL TO OMIT The Closing Tag. In Html Some Elements Do Not Have to Have A Closing Tag. The Following Code Is Legal in HTML:
this is a paragraph
this is another paragraph in Xml All Elements Must Have a closing tag, like this:
this is a paragraph p>
This is another paragraph p> Note: You might have noticed from the previous example that the XML declaration did not have a closing tag This is not an error The declaration is not a part of the XML document itself... IT IS Not An XML Element, And It Should Not Have A Closing Tag.
XML Tags Are Case Sensitive Unlike HTML, XML Tags Are Case Sensitive. With XML, The Tag
All XML Elements Must Be Properly Nested Improper Nesting of Tags Makes No Sense To Xml. In Html Some Elements Can Be Improperly Nested within Each Other Like this:
this text is bold and italic b> i> in Xml All Elements Must Be Properly Nested within Each Other Like this:
this text is bold and italic i> b>
All XML documents must have a root element All XML documents must contain a single tag pair to define a root element. All other elements must be within this root element. All elements can have sub elements (child elements). Sub elements must be correctly nested WITHIN THEIR PARENT ELEMENT:
child>
root>
Attribute values must always be quoted With XML, it is illegal to omit quotation marks around attribute values. XML elements can have attributes in name / value pairs just like in HTML. In XML the attribute value must always be quoted. Study the two XML documents Below. The First One is Incorrect, The Second is Correct:
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note>
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note> The Error In The First Document IS That The Date Attribute In The Note Element IS NOT Quoted. This is the correct: Date = "12/11/2002". This is INCORRECT: DATE = 12/11/2002.
With XML, white space is preserved With XML, the white space in your document is not truncated This is unlike HTML With HTML, a sentence like this:.. Hello my name is Tove, will be displayed like this: Hello my name is Tove , Because HTML Reduces Multiple, Connecutive White Space Characters to a Single White Space.
With XML, CR / LF is converted to LF With XML, a new line is always stored as LF Do you know what a typewriter is Well, a typewriter is a mechanical device which was used last century to produce printed documents:.?. - ) After you have typed one line of text on a typewriter, you have to manually return the printing carriage to the left margin position and manually feed the paper up one line. In Windows applications, a new line is normally stored as a pair of characters :.. carriage return (CR) and line feed (LF) The character pair bears some resemblance to the typewriter actions of setting a new line In Unix applications, a new line is normally stored as a LF character Macintosh applications use only a CR. Character to store a new line.comments in xml the syntax for Writing Comments in xml is similar to this of html.
There is nothing special about XML There is nothing special about XML. It is just plain text with the addition of some XML tags enclosed in angle brackets. Software that can handle plain text can also handle XML. In a simple text editor, the XML tags will be visible and will not be handled specially. In an XML-aware application however, the XML tags can be handled specially. The tags may or may not be visible, or have a functional meaning, depending on the nature of the application.
XML Elements
XML Elements Are Extensible and They Have Relationships. XML Elements Have SIMPLE NAMING RULES.
XML Elements Are Extensible XML Documents Can Be Extended to Carry More Information. Look at The Following XML Note Example:
Note> Let's imagine that we created an application that extracted the
Note> Should the application break or crash? No. The application should still be able to find the
XML Elements have Relationships Elements are related as parents and children To understand XML terminology, you have to know how relationships between XML elements are named, and how element content is described Imagine that this is a description of a book..:
My first XML Introduction TO XML
What is html what is xml XML Syntax
Elements Must Beve A Closing Tag Elements Must Be Properly Nested Imagine That XML Document Describes The Book:
chapter>
chapter>
Book> Book is the root element. Title, prod, and chapter are child elements of book. Book is the parent element of title, prod, and chapter. Title, prod, and chapter are siblings (or sister elements) because they have the same parent.Elements have Content Elements can have different content types. An XML element is everything from (including) the element's start tag to (including) the element's end tag. An element can have element content, mixed content, simple content, or empty content. An element can also have attributes. In the example above, book has element content, because it contains other elements. Chapter has mixed content because it contains both text and other elements. Para has simple content (or text content) because it contains only text. Prod has empty content, because it carries no information. In the example above only the prod element has attributes. The attribute named id has the value "33-657". The attribute named media has the value "paper" .
Element Naming XML Elements Must Follow these Naming Rules:
Names can contain letters, numbers, and other characters Names must not start with a number or punctuation character Names must not start with the letters xml (or XML or Xml ..) Names can not contain spaces Take care when you "invent" element names and follow these simple rules: Any name can be used, no words are reserved, but the idea is to make names descriptive names with an underscore separator are nice Examples:
XML Elements CAN Have Attributes in The Start Tag, Just Like HTML. Attributes Are Used To Provide Additional Information About Elements.
XML Attributes XML elements can have attributes From HTML you will remember this:.
The SRC attribute provides additional information about the IMG element In HTML (and in XML) attributes provide additional information about elements.. : 
Quote Styles, "Female" or 'female'? Attribute Values Must Always Be Enclosed in Quotes, But Either Single OR Double Quotes Can Be Used. For a Person's Sex, The Person Tag Can Be Written Like this:
Use of elements vs. Attributes Data Can Be Stored in Child Elements Or in Attributes:
persons>
Person> In the first example sex is an attribute. In the last, sex is a child element. Both examples provide the same information. There are no rules about when to use attributes, and when to use child elements. My experience is that attributes are handy in HTML, but in XML you should try to avoid them Use child elements if the information feels like data.My Favorite Way I like to store data in child elements The following three XML documents contain exactly the same information..: A Date Attribute IS Used In The First EXAMPLE:
Note> a date element is buy in the second example:
Note> An Expanded Date Element IS Used in The Third: (this is my favorite):
date>
Note>
Avoid Using Attributes? SHOULD you Avoid Using Attributes? Some of the problem:
attributes can not contain multiple values (child elements can) attributes are not easily expandable (for future changes) attributes can not describe structures (child elements can) attributes are more difficult to manipulate by program code attribute values are not easy to test against a Document Type Definition (DTD) - which is used to define the legal elements of an XML document If you use attributes as containers for data, you end up with documents that are difficult to read and maintain Try to use elements to describe data use attributes only to.. Provide Information That Is Not Relected To The Data. Don't End Up Like this (if you think this locks like xml, you have not understood the point): To = "TOVE" from = "jani" Heading = "Reminder" Body = "Don't forget me this weekend!"> Note> An Exception to my Attribute rule Rules always have exceptions My rule about attributes has one exception:. Sometimes I assign ID references to elements These ID references can be used to access XML elements in much the same way as the NAME or ID attributes in HTML. This Example Demonstrates this:
Note>
Note>
Messages> The Id in these Examples Identifier, To Identify The Different Notes in The xml file, and not a part of the note data. What i am trying to say me is that metadata (Data) About data) Should Be Stored As Attributes, And That Data Itself Should Be Stored As Elements.xml Validation
XML with Correct Syntax Is Well FORMED XML. XML Validated Against A DTD IS Valid XML.
. "Well Formed" XML documents A "Well Formed" XML document has correct XML syntax A "Well Formed" XML document is a document that conforms to the XML syntax rules that were described in the previous chapters:
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note>
"Valid" XML Documents A "Valid" XML Document Also Conforms To A DTD. A "Valid" XML Document IS A "Well formed" XML Document, Which Also Conforms To The Rules of A Document Type Definition (DTD):
Xml Version = "1.0" encoding = "ISO-8859-1"?>
Note>
XML DTD A DTD defines the legal elements of an XML document. The purpose of a DTD is to define the legal building blocks of an XML document. It defines the document structure with a list of legal elements. You can read more about DTD, and how to validate your XML documents in our DTD tutorial.XML Schema XML Schema is an XML based alternative to DTD. W3C supports an alternative to DTD called XML Schema. You can read more about XML Schema in our Schema tutorial.
Errors will Stop you Errors in XML documents will stop the XML program. The W3C XML specification states that a program should not continue to process an XML document if it finds a validation error. The reason is that XML software should be easy to write, and that all XML documents should be compatible. with HTML it was possible to create documents with lots of errors (like when you forget an end tag). One of the main reasons that HTML browsers are so big and incompatible, is that they have their own Ways to Figure ut what a document shouth look loo means. with xml this shouth lot not be posible.
A general XML Validator To Help You Validate Your Xml Files, We Have Created This Link So That You Can Validate Any XML File.
XML Browser Support
In Our XML Tutorial We Have Focused On Internet Explorer 5.0 .
XML on this Web Site Many browsers support XML. We are focusing on Internet Explorer 5.0 . Some of you have complained about this, but we think this is the most practical way to demonstrate real XML examples for you over the Internet.
XML in Mozilla Firefox 1.0 Mozilla Firefox 1.0 Supports the XML 1.0 Standard.
XML in Netscape 6 Netscape 6 supports XML To look at the XML source in Netscape 6:.. Right-click on the page and select "View Page Source" .XML in Internet Explorer 5.0 Internet Explorer 5.0 supports the XML 1.0 standard Internet Explorer 5.0 supports most of the international standards for XML 1.0 and the XML DOM (Document Object Model) These standards are set by the World Wide Web Consortium (W3C) Internet Explorer 5.0 has the following XML support..:
Viewing of XML documents Full support for W3C DTD standards XML embedded in HTML as Data Islands Binding XML data to HTML elements Transforming and displaying XML with XSL Displaying XML with CSS Access to the XML DOM Internet Explorer 5.0 also has support for Behaviors:
Behaviors is a Microsoft-only technology Behaviors can separate scripts from an HTML page. Behaviors can store XML data on the client's disk. Examples of all these features are given in the next chapters of this web site.
Viewing XML Files
Raw XML Files Can Be Viewed in Mozilla Firefox, IE 5.0 And in Netscape 6. However, To Make XML Documents to Display Like Nice Web Pages, You Will Have To Add Some Display Information.
Viewing XML Files In Mozilla Firefox and IE 5.0 : Click on a link to an XML file, type the direct URL in the address bar, or double-click on the name of an XML file in a folder 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 element structure to view the raw XML source (without the and - signs ), SELECT "View Source" OR "View Source" from the Browser Menu. in Netscape 6: Open THE XML File (Via a Link OR), The Right-Click In XML File and SELECT "View Page Source". The XML document will then be displayed with color-coded root and child elements Look at this XML file:. note.xml Note:! Do not expect XML files to be formatted like HTML documents Viewing an Invalid XML File If an erroneous XML file is opened , The Browser Will Report The Error. Look at this XML File: Note_ERROR.XML
Other XML Examples Viewing some XML documents will help you get the XML feeling. An XML CD catalogThis is my father's CD collection, stored as XML data (old and boring titles I think .... :-)). An XML plant catalogThis is A Plant Catalog from a Plat Shop, Stored As XML Data. A Simple Food Menuthis Is A Breakfast Food Menu from A Restaurant, Stored As XML Data.
Why does XML display like this? XML documents do not carry information about how to display the data. Since XML tags are "invented" by the author of the XML document, browsers do not know if a tag like
