Learn XML: How to write XML?

zhaozj2021-02-16  44

When writing XML documents, you must follow some rules. However, these rules are usually very simple and easy to understand. Here we will describe these rules.

XML document version

The first row of the XML document is used to define the version of the XML used in this document. The label in the following code defines the version of the XML document used to 1.0.

source code section of c-sharp corner source code section of c-sharp corner GDI Source Code Section of C-Sharp Corner Source Code Section of C-Sharp Corner

XML element name

XML elements cannot contain spaces;

XML elements cannot begin with numbers or punctuation;

XML elements can contain letters, numbers, and other symbols;

Case Sensitive

Unlike HTML, XML is sensitive. Therefore, the

tag and
tag are different; if you write the following code:

this is a section

The XML parser does not parse this statement but gives an error message.

Root node

Each XML document must have a root node. In the above XML document,

is its root node.

Complete label

Each tab of XML must have a corresponding end tag. The code that has not ended the label is invalid. The following code contains an invalid XML tag:

this is a section

Suitable order

Unlike HTML, XML tags cannot be placed casually. For example, the following code is correct in HTML, and is invalid in XML:

this is a section

The correct code should be like this:

this is a section

Space is also part of the XML documentation

Spaces are part of the XML document; and HTML is different, and in XML is displayed in the browser.

Attribute value must be included in a pair of double quotes

The attribute value must be placed in a pair of double quotes, otherwise it is invalid. E.g:

Source Code Section of C-Sharp Corner

In the above code, C # is not included in the double quotes and is therefore invalid.

转载请注明原文地址:https://www.9cbs.com/read-23426.html

New Post(0)