[Introduction] Now let's use Notepad to create our xml file. Let’s look at an XML file first: by Use "Notepad" to create our xml file. First look at an XML file:
Example 1
〈?xml version="1.0" encoding="gb2312" ?〉 〈参考资料〉 〈书籍〉 〈名称〉XML入门精解〈/名称〉 〈作者〉张三〈/作者〉 〈价格 货币单位="人民币"〉20.00〈/价格〉 〈/书籍〉 〈书籍〉 〈名称〉XML语法〈/名称〉 〈!--此书即将出版--〉 〈作者〉李四〈/作者〉 〈价格 货币单位="人民币"〉18.00〈/价格〉 〈/书籍〉 〈/参考资料〉
This is a typical XML file. After editing, it is saved as a file with the .xml suffix. We can divide this file into two major parts: the file preamble (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 character code must be 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
〈!--This book will be published soon--〉This sentence is the same as HTML, it is a comment. In the XML file, the comment part is placed between the "〈!--" and "--〉" tags between parts.
As you can see, XML files are quite simple. Like HTML, XML files are also composed of a series of tags. However, the tags in XML files are our own custom tags and have clear meanings. We can explain the meaning of the content in the tags.
After having a preliminary impression of XML files, let’s talk about the syntax of XML files in detail. Before talking about grammar, we must understand an important concept, which is XML Parse.
1.XML parser
The main function of the parser is to check whether there are structural errors in the XML file, strip the tags in the XML file, and read out the correct content to pass to the next One-step application processing. XML is a markup language used to structure file information. The XML specification has detailed rules on how to mark the structure of files. The parser is software written according to these rules (mostly written in Java). Just like HTML, in the browser, there must be an HTML parser, so that the browser can "read" various web pages composed of HTML tags and display them in front of us. If there are tags that the browser's HTML parser cannot read, an error message will be returned to us.
Because the current HTML tags are actually quite confusing, and there are a lot of non-standard tags (some web pages can be displayed normally with IE, but not with Netscape Navigator), so from the beginning, XML designers The syntax and structure of XML are strictly stipulated. The XML files we write must comply with these regulations, otherwise the XML parser will show you error messages mercilessly.
There are two types of XML files, one is the Well-Formed XML file and the other is the Validating XML file.
If an XML file satisfies certain relevant rules in the XML specification and does not use DTD (document format definition - details later), it can be called Well-Formed. And if an XML file is Well-Formed, the DTD is used correctly, and the syntax in the DTD is correct, then the file is Validating. Corresponding to the two XML files, there are two XML parsers, one is the Well-Formed parser and the other is the Validating parser. IE 5 includes a Validating parser, which can also be used to parse Well-Formed XML files.
Check whether it meets the conditions of Well-Formed. We can open the first XML file we just edited with a browser of IE 5 or above.
You may ask why the display in the browser is the same as my source file? That's right, because for XML files, we only know the content, and its display form is completed by CSS or XSL. Here, we have not defined its CSS or XSL file for this XML file, so it is displayed in its original form. In fact, for electronic data interchange, only an XML file is needed. If we want to display it in some form, we must edit the CSS or XSL file (this issue will be discussed later).
2. Well-Formed XML file
We know that XML must be Well-Formed in order to be correctly parsed by the parser and displayed in the browser. So what is a Well-Formed XML file? There are mainly the following guidelines, which must be met when we create XML files.
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 in HTML without an end tag, XML calls it an "empty element" and you must use The writing method is: 〈empty element name/〉. If the element contains attributes, the writing method is: 〈empty element name attribute name = "attribute value"/〉.
Fourth, marks must not cross. In the previous HTML file, you can write like this: 〈B〉〈H〉XXXXXXX〈/B〉〈/H〉, 〈B〉 and 〈H〉
There are Overlapping areas, but in XML, it is strictly prohibited to write such interleaved tags, and tags must appear in a regular order.
Fifth, the attribute value must be enclosed in " ". Such as "1.0", "gb2312", "RMB" in the first example. They are all enclosed by " " and cannot be missed.
Sixth, English control tags, instructions and attribute names must be case-sensitive. Unlike HTML, in HTML, tags like and have the same meaning, while in XML, tags like
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 "〉" as the end mark. For example: In the source code in Example 2, except for the "〉" symbols, the rest of the content parser will be handed over to the downstream application intact, even if the beginning and end of the CDATA area Blanks and newline characters will also be transferred (note that CDATA is an uppercase character).
## Example 2
〈
RSS and XML are tools for web content management. RSS is used to publish and subscribe to content, and XML is used to store and transfer data. They work with content publishing, subscriptions, and update push. Examples of usage include RSS publishing blog posts and XML storing book information.

RSS documents are XML-based structured files used to publish and subscribe to frequently updated content. Its main functions include: 1) automated content updates, 2) content aggregation, and 3) improving browsing efficiency. Through RSSfeed, users can subscribe and get the latest information from different sources in a timely manner.

The XML structure of RSS includes: 1. XML declaration and RSS version, 2. Channel (Channel), 3. Item. These parts form the basis of RSS files, allowing users to obtain and process content information by parsing XML data.

RSSfeedsuseXMLtosyndicatecontent;parsingtheminvolvesloadingXML,navigatingitsstructure,andextractingdata.Applicationsincludebuildingnewsaggregatorsandtrackingpodcastepisodes.

RSS documents work by publishing content updates through XML files, and users subscribe and receive notifications through RSS readers. 1. Content publisher creates and updates RSS documents. 2. The RSS reader regularly accesses and parses XML files. 3. Users browse and read updated content. Example of usage: Subscribe to TechCrunch's RSS feed, just copy the link to the RSS reader.

The steps to build an RSSfeed using XML are as follows: 1. Create the root element and set the version; 2. Add the channel element and its basic information; 3. Add the entry element, including the title, link and description; 4. Convert the XML structure to a string and output it. With these steps, you can create a valid RSSfeed from scratch and enhance its functionality by adding additional elements such as release date and author information.

The steps to create an RSS document are as follows: 1. Write in XML format, with the root element, including the elements. 2. Add, etc. elements to describe channel information. 3. Add elements, each representing a content entry, including,,,,,,,,,,,. 4. Optionally add and elements to enrich the content. 5. Ensure the XML format is correct, use online tools to verify, optimize performance and keep content updated.

The core role of XML in RSS is to provide a standardized and flexible data format. 1. The structure and markup language characteristics of XML make it suitable for data exchange and storage. 2. RSS uses XML to create a standardized format to facilitate content sharing. 3. The application of XML in RSS includes elements that define feed content, such as title and release date. 4. Advantages include standardization and scalability, and challenges include document verbose and strict syntax requirements. 5. Best practices include validating XML validity, keeping it simple, using CDATA, and regularly updating.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool