search
  • Sign In
  • Sign Up
Password reset successful

Follow the proiects vou are interested in andi aet the latestnews about them taster

Table of Contents
The syntax of Xml
A XML file is divided into the following parts:
Document Declaration
Element
Attributes
Comments
CDATA area, special characters
processing instruction)
Declaration of Xml
attribute : Character encoding if not specified, the default is UTF-8
## <?xml version="1.0" encoding="UTF-8"?>
XmlBasic rules for elements
Xml Tag syntax:
对于XML标签中出现的所有空格和换行,XML解析程序都会当作标签内容进行处理
 如果文本字符中包含了一些特殊的字符,例如<和&由于这些字符都有特殊的含义,因此直接在xml文档中使用该字符串将引起文档的混乱。
   <表达式>
        <比较符>1+3<6</比较符>
   </表达式>
代表的是文本字符串中包含了特殊的字符
有以下两种方法解决:
1、 使用实体引用:用另一个特殊符号代替这些特殊符号
2、
Home Backend Development XML/RSS Tutorial Crazy XML study notes (2)-------------Format requirements

Crazy XML study notes (2)-------------Format requirements

Feb 21, 2017 pm 02:04 PM

The syntax of Xml

        A XML file is divided into the following parts:

##–       Document Declaration

Element

Attributes

Comments

CDATA area, special characters

Processing instructions (processing instruction)

Declaration of Xml

The simplest declaration

<?xml version=”1.0”?>

##Encoding attribute : Character encoding if not specified, the default is UTF-8 encoding

##Common character set

Simplified Chinese:

GBK

or GB2312Traditional Chinese

: BIG5

Western European characters

:ISO8859-1

##Universal international encoding:Unicode UTF-8

Demonstration case:

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

<中国></

中国

>Cause of error Yes:

Encoding error



## is decoded into the characters


xml

Document when the character set is wrong



##The new creation is a .txt
document


What is saved is .xml UTF-8

Default encodingANSI

China

##Write to hard disk

Encoded into binary code

00 11

Disk file


Standalone:Specify whether the document needs to reference other resources,The attribute value is only: yes or no

##Yes:Independent No:Not independent

XML file is the same as HTML file, it is actually a text file.

Obviously everyone will understand immediately that the most common tool for creating XML files is the same as HTML, which is "Notepad".

In addition to "Notepad", of course there are some more convenient tools, such as XML Notepad, XML Pro, and CLIP! XML Editor, etc.

One of the major features of these tools is that they can check whether the XML file you create complies with the XML specification. However, these tools are currently only available in English and require payment.

Of course, you can still use tools such as FrontPage and DreamWeaver, but they are not very convenient to use.

With the gradual popularity of XML, I believe that very useful tools for creating XML files will appear in the near future. Now let's use "Notepad" to create our XML file. First look at an XML file:

Example 1

##〈?xml version="1.0" encoding="gb2312" ?〉

〈References〉
〈Book〉
〈Name〉Introduction to XML 〈/Name〉
〈Author〉Zhang San〈/Author 〉
〈Price Currency Unit="RMB"〉20.00〈/Price〉
〈/Book〉
〈Book〉
〈Name〉XML Syntax〈/Name〉
〈!-- This book will be published soon--〉
〈Author〉Li Si〈/Author〉
〈Price Currency Unit="RMB"〉18.00〈/Price〉
〈/Book〉
〈/Reference Materials 〉

This is a typical XML file. After editing, save it as a file with the .xml suffix. We can divide this file into two major parts: the file preface (Prolog) and the file body.


The first line in this file is the file preamble. This line is something that an XML file must declare, and it must also be located on the first line of the XML file. It mainly tells the XML parser how to work.

Among them, version is the standard version number used by this XML file, which is required; encoding specifies the character type used in this XML file, which can be omitted. When you omit this statement, the following The character code must be a Unicode character code (it is recommended not to omit it)

. Because we are using GB2312 character code in this example, the encoding statement cannot be omitted. There are also some declaration statements in the preamble of the file, which we will introduce later.

The rest of the file belongs to the file body, and the content information of the XML file is stored here.


We can see that the main body of the file is composed of the starting and the ending control tag. This is called the "root element" of the XML file; is used as a direct It belongs to the "child elements" under the root element; under there are sub-elements such as , , and . The currency unit is an "attribute" in the element, and "RMB" is the "attribute value".

First of all, the first line of the XML file must declare that the file is an XML file and the XML specification version it uses. There cannot be other elements or comments in front of the file.


Second, there can be only one root element in an XML file. In our first example, 〈References〉... 〈/References〉 is the root element of this XML file.


Third, the tags in the XML file must be closed correctly, that is, in the XML file, the control tag must have a corresponding closing tag. For example: the tag must have a corresponding closing tag. Unlike HTML, the closing tag of some tags is optional. If you encounter a self-contained unit tag in an XML file, which is similar to Crazy XML study notes (2)-------------Format requirements in HTML and does not have an end tag, XML calls it "empty". Element" must be written like this: 〈empty element name/〉. If the element contains attributes, it must be written like this: 〈empty element name attribute name="attribute value"/〉.


Fourth, marks must not cross. In the previous HTML file, you could write like this:

〈B〉〈H〉XXXXXXX〈/B〉〈/H〉,〈B〉 and 〈H〉
There are overlapping areas between the tags, and In XML, such interleaving of tags is strictly prohibited, and tags must appear in a regular order.


Fifth, attribute values ​​must be enclosed in " " signs. Such as "1.0", "gb2312", "RMB" in the first example. They are all enclosed by " " symbols and cannot be omitted.


Sixth, English control tags, instructions and attribute names must be case-sensitive. Different from HTML, in HTML, tags like and have the same meaning, while in XML, tags like , or are different


Seventh, we know that in HTML files, if we want the browser to display the things we input intact, we can put these things in 〈pre〉〈/pre〉 or 〈xmp〉〈/xmp〉 marks the middle. This is essential for us to create HTML teaching web pages, because the source code of HTML must be displayed in the web page. In XML, to implement such a function, CDATA tags must be used. The information in the CDATA tag is passed intact to the application by the parser, and any control tags in the segment of information are not parsed. The CDATA area is marked by "


XmlBasic rules for elements

##Elements are part of the xml document The basic unit , xml document is composed of elements nested layer by layer. The entire xml document starts from the root element,The root element contains several sub-elements,and each sub-element can contain several sub-elements,So that a xml document can be formed.

Xml Tag syntax:

## 1, ## The tags of #Xml are divided into two categories:

#Single tag:

<中国/>#Double mark:

<

中国></中国>## 2, xml tag requirements:

## 1. Tag names can contain letters ( includes non-Western European characters

)

, numbers, underscores (_), and underscores (-), colon (:) and period (.) form , but cannot start with numbers, dashes or periods. 2, tag name cannot contain <,

>

,,,$ and other symbols 3, try not to have English colons (:), in label names unless you are using a namespace.

4, tag name cannot start with any combination of upper and lower case characters such as xml,

XML

, etc. #5, tag name cannot contain spaces.

6, tag names are case-sensitive

3, xml Tag nested sub-elements: xml allows deep nesting of sub-elements, as long as reasonable nesting between elements is ensured That is .And the xml element can nest multiple sub-elements with the same name,these multiple sub-elements are in order.

First:xml

##<China >

## <Beijing>

; <Haidian/>

# ; <

Chaoyang></Chaoyang >## <

Chaoyang

></Chaoyang>## </Beijing

>

##</ China>

##Secondxml

##<China>

## <Beijing>

##​ <Chaoyang></Chaoyang>

; ##/>## </Beijing

>

</中国>

##4, empty element: empty element cannot accept child elements, also cannot accept string content.

##                                                 xml:

                                 

#                                                                                                                              And can accept multiple attributes </book>

<book>                                                                                                                                                                      

##         </book>For example, an empty element accepts attributes:

  <book name=”Java建议” price=”30”/>

5、字符数据

   <book>

      <computer>Struts2开发详解</computer>

      <computer>

         Struts2开发详解

      </computer>

   </book>

  对于XML标签中出现的所有空格和换行,XML解析程序都会当作标签内容进行处理

 如果文本字符中包含了一些特殊的字符,例如<&由于这些字符都有特殊的含义,因此直接在xml文档中使用该字符串将引起文档的混乱。

<表达式>

 

        <比较符>1+3<6</比较符>

   </表达式>

代表的是文本字符串中包含了特殊的字符

 

有以下两种方法解决:

1、 使用实体引用:用另一个特殊符号代替这些特殊符号

2、使用CDATA标记:将整个文档定义成字符串。

1、  使用实体引用

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

  <表达式>

        <比较符>1+3&<6</比较符>

  </表达式>

上面的红色的<产生了干扰

解决如下:

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

  <表达式>

        <比较符>1+3&lt;6</比较符>

                                                                                                                                                                                                   ​                              ; Tag

Under the special tag

CDATA,all special characters,are even valid elements will be treated as simple strings. Entity references also lose their effect and become direct text. The syntax format of

CDATA is as follows:

##< ![CDATA[Text content]]>

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

                                                                                                                                 +3<6

]]>

# </Expression>

# Note: Since the

xml

document will not perform any parsing of the CDATA tag content at all

,

, therefore any content can be placed within CDATA, where The content is never wrong.

1, Comment

##XmlThe document can also add character data for explanation,These strings used for interpretation will not be processed by the xml parser. These explanatory texts are called notes. The documentation comments of Xml

are exactly the same as

html. XmlThe syntax format of comments is as follows: <!--

Comment characters String

-->

Comments for Xml are allowed to contain elements and tags. Note: 1, Xml

comments cannot be placed in the tag body.

2,

Do not put the

xml document before the xml document declaration xml document The declaration is always on the first line

3, Do not use double underscores in comments (--)

…..

##2, Processing instructions

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

Processing instructions are used to provide information to applications that process xml documents, telling the processor how to process the document. A complete xml document processing program, can read the xml document processing instructions, and perform corresponding processing according to the processing instructions,Or pass it to the next program.

XmlThe format of the processing instruction is as follows:

<?Processing instruction name processing Command information?>

##3、 Attribute

xmlCharacteristics of attributes:

1, xmlThe attribute of the element must have an attribute value,The attribute value must be enclosed in quotation marks.

2, The same xml element cannot have multiple attributes with the same name

##3, XmlThere is no order among the multiple attributes in the element.

&lt;book&gt;
     &lt;isbn&gt;123456780&lt;/isbn&gt;
     &lt;book_name&gt;Java讲义&lt;/book_name&gt;
      &lt;price&gt;99&lt;/price&gt;
&lt;/book&gt;


For example, this

book itself has isbn book_name price The properties of

then

&lt;book isbn=”” book_name=”” price=””/&gt;


##Xml

There must be a root element.

Xml

The overall structure of the document##1,

There must be a root element

(There is and only one)##2, The element must end reasonably

3, Elements must be nested reasonably

4, The attributes of elements must have attribute values

As long as the above conditions are not met, it is a poorly formatted documentxmlDocument

##As long as the above conditions are met, it is a well-formatted documentxmlDocument

and comply with dtd or schema

is a valid

xml document. XmlDocument is a standard structured document that can be converted into DOM (Document Object Model)

Tree

,The root node corresponds to the root node of the DOM tree.

&lt;book&gt;
    &lt;computer&gt;
       &lt;name&gt;网上介绍&lt;/name&gt;
       &lt;author&gt;redarmy&lt;/author&gt;
    &lt;/computer&gt;
    &lt;computer&gt;
        &lt;name&gt;网上介绍&lt;/name&gt;
       &lt;author&gt;redarmy&lt;/author&gt;
    &lt;/computer&gt;
&lt;/book&gt;



#book


#computer


#computer


#…………


##computer


#name


##author

Notice:

Must have a root tag and the root tag must be unique

The start tag and the end tag need to be used in pairs

Marks cannot be used interchangeably

Empty markers can be written in the form of "

<tag name/>"

Marks are case-sensitive

The above are the crazy XML study notes (2)--------- ----Format required content, please pay attention to the PHP Chinese website (m.sbmmt.com) for more related content!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Popular tool

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

JSON vs. XML: Why RSS Chose XML JSON vs. XML: Why RSS Chose XML May 05, 2025 am 12:01 AM

RSS chose XML instead of JSON because: 1) XML's structure and verification capabilities are better than JSON, which is suitable for the needs of RSS complex data structures; 2) XML was supported extensively at that time; 3) Early versions of RSS were based on XML and have become a standard.

Understanding RSS Documents: A Comprehensive Guide Understanding RSS Documents: A Comprehensive Guide May 09, 2025 am 12:15 AM

RSS documents are a simple subscription mechanism to publish content updates through XML files. 1. The RSS document structure consists of and elements and contains multiple elements. 2. Use RSS readers to subscribe to the channel and extract information by parsing XML. 3. Advanced usage includes filtering and sorting using the feedparser library. 4. Common errors include XML parsing and encoding issues. XML format and encoding need to be verified during debugging. 5. Performance optimization suggestions include cache RSS documents and asynchronous parsing.

Building XML Applications with C  : Practical Examples Building XML Applications with C : Practical Examples May 03, 2025 am 12:16 AM

You can use the TinyXML, Pugixml, or libxml2 libraries to process XML data in C. 1) Parse XML files: Use DOM or SAX methods, DOM is suitable for small files, and SAX is suitable for large files. 2) Generate XML file: convert the data structure into XML format and write to the file. Through these steps, XML data can be effectively managed and manipulated.

RSS, XML and the Modern Web: A Content Syndication Deep Dive RSS, XML and the Modern Web: A Content Syndication Deep Dive May 08, 2025 am 12:14 AM

RSS and XML are still important in the modern web. 1.RSS is used to publish and distribute content, and users can subscribe and get updates through the RSS reader. 2. XML is a markup language and supports data storage and exchange, and RSS files are based on XML.

XML in C  : Handling Complex Data Structures XML in C : Handling Complex Data Structures May 02, 2025 am 12:04 AM

Working with XML data structures in C can use the TinyXML or pugixml library. 1) Use the pugixml library to parse and generate XML files. 2) Handle complex nested XML elements, such as book information. 3) Optimize XML processing code, and it is recommended to use efficient libraries and streaming parsing. Through these steps, XML data can be processed efficiently.

Beyond Basics: Advanced RSS Features Enabled by XML Beyond Basics: Advanced RSS Features Enabled by XML May 07, 2025 am 12:12 AM

RSS enables multimedia content embedding, conditional subscription, and performance and security optimization. 1) Embed multimedia content such as audio and video through tags. 2) Use XML namespace to implement conditional subscriptions, allowing subscribers to filter content based on specific conditions. 3) Optimize the performance and security of RSSFeed through CDATA section and XMLSchema to ensure stability and compliance with standards.

Understanding RSS: An XML Perspective Understanding RSS: An XML Perspective Apr 25, 2025 am 12:14 AM

RSS is an XML-based format used to publish frequently updated content. 1. RSSfeed organizes information through XML structure, including title, link, description, etc. 2. Creating RSSfeed requires writing in XML structure, adding metadata such as language and release date. 3. Advanced usage can include multimedia files and classified information. 4. Use XML verification tools during debugging to ensure that the required elements exist and are encoded correctly. 5. Optimizing RSSfeed can be achieved by paging, caching and keeping the structure simple. By understanding and applying this knowledge, content can be effectively managed and distributed.

Inside the RSS Document: Essential XML Tags and Attributes Inside the RSS Document: Essential XML Tags and Attributes May 03, 2025 am 12:12 AM

The core structure of RSS documents includes XML tags and attributes. The specific parsing and generation steps are as follows: 1. Read XML files, process and tags. 2. Extract,,, etc. tag information. 3. Handle custom tags and attributes to ensure version compatibility. 4. Use cache and asynchronous processing to optimize performance to ensure code readability.

Related articles