[XML entry series] Chapter 2 _ xml Basics

Source: Internet
Author: User
Tags cdata processing instruction xml attribute xsl
[XML entry series] Chapter 2 _ xml basics -- v512 studio Editor: Xuan Yu
Introduction Attribute Main Applications   Cpoyright
Instance Element Entity reference My blog
Statement Root element Good format V512 Studio
Tag Handling instructions CDATA and comments Chinese Emy of Sciences

Differences between XML and HTML
HTML is the most basic technology for Internet applications. It focuses on data display. Its core function is information layout and display.
All the tags in HTML are fixed. To add new tags, you must redevelop new standards to enable browser recognition.
Both GML and SGML are the ancestor of HTML and XML. xml and HTML are very different. The relationship between the two is a cousin, which is equivalent to HTML being the cousin of XML.

XML (eXtensible
Markup Language) is a scalable Markup Language similar to HTML. It can be directly displayed in IE and other browsers
XML file structure. All XML files are composed of the following modules: elements, attributes, entities, pcdata (text content), and CDATA
All XML tags are custom. You can also customize Chinese tags. It is designed to include and transmit data, that is, carrying data. Its typical extension is *. xml.
XML is not a technology used to replace html. They are designed for different purposes. The core of the XML design is to include and transmit data, and the core of the HTML design is to display data.
XML W3C recommendation standard, W3C is an Internet management organization. The latest version of XML 1.0, XML standard URL: http://www.w3.org/TR/REC-xml/
XML is a big Technical System with a lot of content. Such as SVG, SMIL, hdml, and oeb, including a combination of XHTML and HTML.
XML, as a big technical framework, is applied in many fields, such as e-commerce, biotechnology, chemistry, and mathematics. Because it involves carrying data, many industries can use XML to represent some data

GML (1, 1969) General Markup Language
SGML (1, 1985) Standard General Markup Language
HTML (1, 1993) Hypertext Markup Language
XML (1, 1998) Extensible Markup Language
XHTML Extensible Hypertext Markup Language
SVG Scalable Vector Graphics Language
SMIL Synchronous multimedia integrated language
Hdml Handheld device Markup Language
...... ......
Oeb Open electronic structure Specification

Main XML applications
As the system configuration file
Applicationcontext. XML in spring
Hibernate. cfg. XML in hibernate
Struts. XML in struts2
Log4j. XML in log4j
Web. XML in Web Applications
Server. XML in Tomcat
Data transmission in Ajax: the server needs to transmit data to the browser, and the transmitted data is transmitted in XML format.
Data transmission in Web Services: its data is also transmitted in XML format, including some protocols involved in it. The protocol is also developed using XML.
Data exchange and integration on Heterogeneous Platforms: for example, developing a large-scale bank check exchange system. Summarize the check information of each bank and then complete the electronic exchange.
Every banking system involved is different. How can I complete the payment?
In fact, they can collect check information in XML format, and then process, exchange, integrate, and process them.
Because XML is cross-platform, different platforms can use XML to carry data.
The reason why XML is used as the configuration file: in many development frameworks, XML is used as the configuration file, because it carries data and is very convenient for post-processing.
Because XML can easily read its configuration content through Java APIs, it is not very convenient to use other
So now we apply the framework or some class libraries. If there are configuration files, 80-90% are all XML files.

XML instance
<? XML version = "1.0" encoding = "UTF-8"?>
<Book list>
<Computer books>
<Title> the present and present of XML </title>
<Price> 66.66 </price>
</Computer books>
</Book list>
Note ①: when the text editor saves the XML file, the storage type and encoding should be saved as the declared value type. Otherwise, the browser reports an error.
Note ②: an XML file can only have one root element. Here is the <book list>. However, the number of sub-elements is not limited. Here there can be multiple <computer books>

XML Declaration (<? XML version = "1.0" encoding = "UTF-8"?>)
Most XML files start with XML declarations. They provide basic information about documents.
If the XML file does not start with an XML declaration, it can be said that...
Version indicates the XML version. Encoding indicates the character encoding method used by the XML file

Label (text between Left angle brackets (<) and right angle brackets (>)
Start tag. Example: <Name>
End tag. Example: </Name>

Root element
An XML file must have only one root element.
The structure of an XML file is a tree structure that begins with "root" and extends to "branches"
XML content must be contained in a single element. This single element is called the root element. It contains all text and all other elements in the document.

Element (start tag, end tag, and all content between the two)
The elements are case sensitive. For example, <bookname> XML current and current </bookname> reports an error.
The element must be correctly nested. For example, <bookname> XML <price> </bookname> 39.00 </price> May report an error.
The element must be properly disabled. For example, an error occurs in the current and current versions of <bookname> XML.
Normal output of null elements, such as <bookname/> or <bookname> </bookname>. <bookname/>
Parent and Child elements, for example:
<Book>
<Author>
<Name> Liu Wei </Name>
<Email> liuwei8809@163.com </Email>
</Author>
<ISBN> 12345 </ISBN>
</Book> <! -- If it is written as </book>, an error is returned because the <book> end tag cannot be found </book> -->

Entity reference (to avoid confusion between character data and some special symbols used in tags, XML provides entity reference)

Character Entity reference
& & Amp;
> & Gt;
< & Lt;
" & Quot;
' & Apos;

<Name> <XML application >></Name> an error occurs during running.
<Name> & lt; XML application overview & gt; </Name> running output: <Name> <XML application overview> </Name>

Attribute (a value is required, and the value must be enclosed in quotation marks)
You can use single or double quotation marks, but always keep them consistent.
An XML file has many attributes, either using single quotation marks or double quotation marks (double quotation marks are recommended)
<Bookname ISBN = "xxx123"> XML application overview </bookname> is correct.
<Bookname ISBN = 'xxx123 '> XML application Daquan </bookname> is correct, but ie outputs are all in double quotation marks
<Bookname ISBN = 'xxx123 "> XML application Daquan </bookname> is incorrect, because single quotation marks and double quotation marks cannot be used together.

CDATA and comments
All tags and entity references are ignored in special tag CDATA, which are treated as character data by XML processing programs.
CDATA format: <! [CDATA [text content]>
Note: <! -- And --> (sometimes, if you want to disable some XML content, you can put it in the comment)
Example: an error occurs during <Name> <''" XML application overview "''> </Name>.
<Name> <! [CDATA [<''" XML application overview "''>]> </Name> normal output during runtime <''" XML application overview "''>
<! -- This is the comment I added -->

Processing Instruction Pi (processing instructions, indicating how the content of the current XML file is displayed or processed)
Syntax: <? Target Arg *?>
Example: Use XSLT to process the current XML file: <? XML-stylesheet type = "text/XSL" href = "book. XSL"?>

Well-formatted XML (XML with correct syntax)
The XML verified by DTD is "legal" XML
Well-formed XML complies with the following XML syntax rules:
The XML file must have a root element.
The XML file must have a close tag.
XML tags are case sensitive.
XML elements must be correctly nested
The XML Attribute must be enclosed in quotation marks.

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.