Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of XML principle

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail the example analysis about the principle of XML. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Example:

George John Reminder Don't forget the meeting!

An example is explained:

The first line is the XML declaration. It defines the version of XML (1. 0) and the encoding used (ISO-8859-1 = Latin-1/ Western European character set).

Describe the root element of the document

/ / the beginning of the root element * / / the end of the root element

4 child elements

George John Reminder Don't forget the meeting!

In this way, the XML document forms a tree structure as follows:

George John Reminder George John Reminder

All XML elements must be related to a closed tag

This is a paragraph / / error

This is a paragraph

/ / A pair

XML tags are case sensitive

This is wrong. / / No, this is correct. / / A pair

XML must be properly nested

This text is bold and italic / / wrong This text is bold and italic / / a pair

Attribute values of XML must be in quotation marks

/ / wrong George John / / A pair of George John

Entity reference: a change of meaning for a special character.

< < 小于 >

> greater than

& & and sign

& apos; 'single quotation marks

"" quotation marks

If salary < 1000 then

What you want:

If salary < 1000 then

Comments in XML

In XML, spaces are retained

HTML cuts (merges) multiple consecutive space characters into one:

HTML:Hello my name is David. Output: Hello my name is David.

In XML, spaces in the document are not abridged.

XML element

Start the tag until (and include) the portion of the tag. Such as:

John

Elements can contain other elements, text, or a mixture of both. Elements can also have attributes. Such as:

/ / category (attribute) child element of Harry Potter / / book, which has only text content J K. Rowling 2005 29.99

XML naming rules

The XML element must follow the following naming convention:

Names can contain letters, numbers, and other characters

Names cannot start with numbers or punctuation

The name cannot start with the character "xml" (or XML, Xml)

The name cannot contain spaces

XML element vs. Attribute

/ / attribute Anna Smith female / / element Anna Smith

There are no rules that tell us when to use attributes and when to use child elements, in XML

You should avoid using attributes as much as possible. If the information feels like data, use child elements.

Property cannot contain multiple values (elements can)

Attribute cannot describe the tree structure (elements can)

Properties are not easy to expand (for future changes)

Properties are difficult to read and maintain

XML Namespace (XML Namespaces)

The XML namespace provides a way to avoid element naming conflicts.

This XML document carries information from a table:

Apples Bananas

This XML document carries information about the table (a piece of furniture):

African Coffee Table 80 120

Naming conflicts occur because both documents contain elements with different contents and definitions.

Use prefixes to avoid naming conflicts

Apples Bananas African Coffee Table 80 120

Use namespaces (Namespaces)

Apples Bananas

This XML document carries information about a piece of furniture:

African Coffee Table 80 120

Default namespace (Default Namespaces)

Defining a default namespace for an element saves us the work of using prefixes in all child elements.

Apples Bananas

This XML document carries information about a piece of furniture:

African Coffee Table 80 120

Namespaces are the nearest principle

Data in a / / default namespace data in b / / w namespace data in e / / proximity policy

CDATA

The term CDATA refers to text data (Unparsed Character Data) that should not be parsed by an XML parser. (that is, the data in it is not parsed by XML)

The CDATA section ends with "":

/ / this is the end of the article on "sample Analysis of XML principles". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report