[XML] basic Tutorial: briefly introduces the features, usage, and structure features of XML

Source: Internet
Author: User

What is XML?
1. xml refers to the Extensible Markup Language)
2. XML is a markup language, similar to HTML
3. XML is designed to transmit data rather than display data.
4. the XML tag is not predefined. You need to customize the tag.
5. XML is designed to be self-descriptive.
6. XML is W3C recommendation Standard

Main differences between XML and HTML
XML is not an alternative to HTML.
XML and HTML are designed for different purposes:
XML is designed to transmit and store data, with the focus on data content.
HTML is designed to display data. Its focus is on the appearance of the data.
HTML is designed to display information, while XML is designed to transmit information.


XML with no behavior

XML is not used.
This may be hard to understand, but XML won't do anything. XML is designed to structure, store, and transmit information.
The notes John wrote to George are stored as XML:

<note><to>George</to><from>John</from>

The above note is self-descriptive. It has the title and message, and contains the information of the sender and receiver.

However, this XML document has not done anything. It is just pure information encapsulated in XML tags. We need to write software or programs to send, receive, and display this document.


XML is only plain text
XML is nothing special. It is just plain text. Any software capable of processing plain text can process XML.
However, applications that can read XML can process XML tags in a targeted manner. The functional meaning of a tag depends on the characteristics of the application.
You can use XML to create your own tags.
The labels in the preceding example are not defined in any XML standards (such as <to> and <from> ). These tags were invented by the creator of the document.
This is because XML does not have predefined labels.
The tags used in HTML (and the HTML structure) are predefined. HTML documents only use tags defined in HTML standards (such as <p> and

XML allows creators to define their own labels and their own document structures.


XML is not an alternative to HTML.
XML is a supplement to HTML.
XML does not replace html. It is important to understand this. In most web applications, XML is used to transmit data, while HTML is used to format and display data.

The best description of XML is:
XML is an information transmission tool independent of software and hardware.


XML usage:

1. XML separates data from HTML
If you need to display dynamic data in HTML documents, it will take a lot of time to edit HTML whenever the data changes.
With XML, data can be stored in an independent XML file. In this way, you can focus on HTML layout and display, and make sure that you do not need to make any changes to HTML to modify the underlying data.
By using several lines of JavaScript, you can read an external XML file and update the data content in HTML.


2. Simplified data sharing in XML
In the real world, computer systems and data are stored in incompatible formats.
XML data is stored in plain text format. Therefore, a data storage method independent of software and hardware is provided.
This makes it easier to create data that can be shared by different applications.


3. Simplified XML Data Transmission
With XML, data can be easily exchanged between incompatible systems.
One of the most time-consuming challenges for developers is the exchange of data between incompatible systems on the Internet.
Since data can be read through a variety of incompatible applications, exchanging data in XML reduces this complexity.
Simplified XML platform change
Upgrading to a new system (hardware or software platform) is always time-consuming. A large amount of data must be converted, and incompatible data is often lost.
XML data is stored in text format. This makes it easier for XML to expand or upgrade to a new operating system, application, or browser without losing data.


4. XML makes data more useful
Because XML is independent of hardware, software, and applications, XML makes your data more available and useful.
Different applications can access your data, not only on HTML pages, but also from XML data sources.
With XML, your data can be used by a variety of reading devices (handheld computers, voice devices, news readers, etc.), and for blind or other persons with disabilities.


5. XML is used to create a new Internet language.
Many new Internet languages are created using XML:
Examples include:

  • XHTML-Latest html Version
  • WSDL-used to describe available Web Services
  • WAP and WML-markup language for handheld devices
  • RSS-language for RSS Feed
  • RDF and owl-used to describe resources and Ontology
  • SMIL-used to describe web-targeted multimedia

XML documents form a tree structure that begins with "root" and expands to "branches ".


An XML document instance
XML uses simple self-descriptive Syntax:

<?xml version="1.0" encoding="ISO-8859-1"?><note><to>George</to><from>John</from>

The first line is the XML declaration. It defines the XML version (1.0) and the encoding used (ISO-8859-1 = Latin-1/Western European character set ).
The following line describes the root element of the document (for example, "this document is a note "):

<Note>


The following four lines describe the four child elements (to, from, heading, and body) of the root ):
<To> George </to>
<From> JOHN </from>
<Heading> reminder <Body> don't forget the meeting! </Body>

The last line defines the end of the root element:
</Note>

In this example, we can imagine that the XML document contains a signature John gave George.

XML documents form a Tree Structure
The XML document must contain the root element. This element is the parent element of all other elements.
The elements in the XML document form a document tree. The tree starts from the root and expands to the bottom of the tree.
All elements can have child elements:

<root>  <child>    <subchild>.....</subchild>  </child></root>

Terminologies such as parent, child, and compatriot are used to describe the relationship between elements. The parent element has child elements. Child elements at the same level become siblings ).
All elements can have text content and attributes (similar to HTML ).


Instance


Represents a book in the following XML:

<bookstore><book category="COOKING">  <title lang="en">Everyday Italian</title>  <author>Giada De Laurentiis</author>  <year>2005</year>  <price>30.00</price></book><book category="CHILDREN">  <title lang="en">Harry Potter</title>  <author>J K. Rowling</author>  <year>2005</year>  <price>29.99</price></book><book category="WEB">  <title lang="en">Learning XML</title>  <author>Erik T. Ray</author>  <year>2003</year>  <price>39.95</price></book></bookstore>

In this example, the root element is <bookstore>. All <book> elements in the document are included in <bookstore>.
The <book> element has four child elements: <title>, <author>, <year>, and <price>.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.