Initial knowledge of XML base _xml

Source: Internet
Author: User
Tags cdata processing instruction xml attribute xml parser

Xml

What is XML?

XML refers to Extensible Markup Language (extensible Markup Language)

XML is a markup language, very similar to HTML

XML is designed to transfer data, not to display data

XML tags are not predefined. You need to define the label yourself.

XML is designed to be self-describing.

XML is the recommended standard for the consortium

The fundamental goal of XML language is to describe the relational data that is often present in real life.

In the XML language, it allows the user to customize the label. A label is used to describe a piece of data; a label can be divided into start and end tags, and other tags can be used to describe other data in between the start and end tags, to achieve a description of the data relationship. For example:

<?xml version= "1.0" encoding= "UTF-8"?>

< China >

< Beijing >

< Haidian ></Haidian >

< Fengtai ></Fengtai >

</Beijing >

< Hunan >

< Changsha ></Changsha >

< Yueyang ></Yueyang >

</Hunan >

< Hubei >

< Wuhan ></Wuhan >

< Jingzhou ></Jingzhou >

</Hubei >

</China >

XML Common applications

In addition to saving relational data, XML technology is often used as a software configuration file to describe the relationship between program modules.

In a software system, to improve the flexibility of the system, the modules it starts are usually determined by its configuration file

For example, a software at the start, it needs to start a, b two modules, and a, b these two modules at the start, but also need A1, A2 and B1, B2 module support, in order to accurately describe this relationship, this time the use of XML files is the most appropriate.

Classification of XML documents

Malformed (malformed) XML document: An XML document that has absolutely no adherence to the basic specification of an XML document.

Well-Formed (well-formed) but invalid XML document: An XML document that adheres to the basic specification of an XML, but does not use a DTD or schema to define semantic constraints.

Valid (valid) XML documents: Adhere to the basic specification of an XML document and use a DTD or schema to define semantic constraints, and also fully adhere to XML documents with DTD or schema-defined semantic constraints.

Well-written XML document

Well-Formed or well structured XML documents have the correct syntax.

The well-formed (well formed) XML document follows the XML syntax rules described in the previous chapters:

The XML document must have a root element

The XML document must have a close tag

XML tags are case sensitive

XML elements must be nested correctly

XML attribute must be quoted

XML syntax

An XML file is divided into the following sections:

Document Declaration

Elements

Property

Comments

CDATA areas, special characters

Processing instructions (processinginstruction)

When writing an XML document, you need to first declare the type of the XML document by using a document declaration.

The simplest declarative Syntax:

<?xmlversion= "1.0"?>

Use the Encoding property to describe the document's character encoding:

<?xmlversion= "1.0" encoding= "GB2312"?>

Use the standalone property to indicate whether the document is independent:

<?xmlversion= "1.0" encoding= "GB2312" standalone= "yes"?>

Common errors:

1. <?xml version=1.0?>

2. <?xml version= "1.0"?> in "and" there is no space between

3. Coding Error

Note: The declaration must be the first line of content in the XML document. < cannot have any other characters before

An XML element refers to a label that appears in an XML file, one labeled as a start tag and an end tag, and a label that has several forms of writing, such as:

Include tag body:<a>www.itcast.cn</a>

:<a/> with no label body

You can also nest several child tags in a label. However, all tags must be reasonably nested, and no cross nesting is allowed, for example:

<a>welcometo <b>www.it315.org</a></b>

Well-Formed XML documents must have and have only one root tag, and other tags are descendants of this root tag.

XML parsers are processed as label content for all the spaces and lines that appear in the XML tag. For example: The meaning of the following two paragraphs is not the same.

First paragraph:

< URL >www.itcast.cn</url >

Second paragraph:

< website >

www.itcast.cn

</website >

Because in XML, spaces and newline are processed as raw content, the "good" writing habits that make the contents of the original file readable by using line-wrapping and indentation can be forced to change when writing an XML file.

Naming conventions

An XML element can contain letters, numbers, and other visible characters, but you must adhere to some of the following specifications:

case-sensitive, such as,<p> and <p> are two different tags.

You cannot start with a number or a "_" (underscore).

Cannot begin with XML (or XML, or XML, etc.).

Cannot contain spaces.

The name cannot contain a colon (:) in the middle.

(1) The English name must begin with an English letter or an underscore, and the Chinese name must begin with a Chinese text or an underscore.

(2) In the case of using the default encoding set, the name can consist of an English letter, a number, an underscore, a connector (-), and a point number (.). In the case of a specified encoding set, the name in addition to the above characters, you can also appear in the character set of legitimate characters

Property

A label can have multiple properties, each of which has its own name and value, for example:

<inputname= "Text" >

Attribute values must be enclosed in double quotes (") or single quotes (')

Defining attributes must follow the same naming conventions as labels

Learn more: In XML technology, the information that the label attribute represents can also be changed to describe in the form of a child element, for example:

<input>

<name>text</name>

</input>

Comments

Annotations in the XML file are formatted as "<!--annotation-->".

Attention:

XML declaration cannot have comments before

Annotations cannot be nested, for example:

<!--large section notes

......

<!--local annotation-->

......

-->

CDATA Area

When writing an XML file, some content may not want the parsing engine to parse execution, but rather as raw content processing.

In this case, the content can be placed in a CDATA area, and the XML parser does not process the content within the CDATA area, but rather the output directly intact.

Syntax: <! [Cdata[content]]>

<! [cdata[

<csdn>

<br/>

</csdn>

]]>

Escape character

For some individual characters, you can also use an escaped form if you want to display their original styles.

Processing instructions

Processing instructions, referred to as pi (processing instruction). Processing instructions are used to direct the parsing engine to parse XML document content.

For example, you can use the Xml-stylesheet directive in an XML document to notify the XML parsing engine and apply a CSS file to display the contents of an XML document. <?xml-stylesheet type= "Text/css" href= "1.css"?>

The processing instruction must be ".??" As the beginning, with "?>" as the end, the XML declaration statement is the most common kind of processing instruction.

CSS does not work when label is in Chinese

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.