Table of Contents
Chapter 1 What is XML? Quick introduction to XML
1. What is XML? First, let's take a look at a piece of code
2.What is XML mainly used for?
3. Quick introduction to XML
Home Backend Development XML/RSS Tutorial Quick Start Tutorial for XML

Quick Start Tutorial for XML

Apr 04, 2017 am 10:54 AM

<p><br></p> <h2 id="Chapter-What-is-XML-Quick-introduction-to-XML">Chapter 1 What is XML? Quick introduction to XML</h2> <h3 id="What-is-XML-First-let-s-take-a-look-at-a-piece-of-code">1. What is XML? First, let's take a look at a piece of code </h3> <p><strong>XML</strong> (Extensible Markup Language) </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE class [ <!ELEMENT class ANY>     <!ELEMENT person (name,time,msg,data)>     <!ELEMENT name (#PCDATA)>     <!ELEMENT time (#PCDATA)>     <!ELEMENT msg (#PCDATA)>     <!ELEMENT data (#PCDATA)> ]> <class>     <person>         <name>0x584A</name>         <time>2015年9月25日 10:24:41</time>         <msg>holle,world!</msg>         <!--这里是CDATA区间-->         <data><![CDATA[<XML的那些事...> -> 跟随0x584A、学习XML.. ]]></data>     </person> </class></pre><div class="contentsignin">Copy after login</div></div> <p> Let's take a look at the specific display effect after running in the browser: </p> <p class="image-package"><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/164/729e3f29ba6f560af48f387edc5ab46c-0.png" class="lazy" alt="Quick Start Tutorial for XML" ><br></p> <p class="image-caption">1.png</p> <h3 id="What-is-XML-mainly-used-for">2.What is XML mainly used for? </h3> <p> I believe that students who have been online for a long time have seen files with the suffix <strong>.xml</strong>. This is what we call <strong>XML</strong> files. <br>First after <strong>HTML</strong> became popular, the <strong><a href="http://www.php.cn/wiki/1550.html" target="_blank">W3C</a></strong> organization felt that the limitations of the HTML language were too great, so it introduced XML for the purpose of <strong> Replace HTML language </strong>. </p> <p>Of course, it seems that W3C’s plan has not been successful. <code>(However, there are no eggs⊙﹏⊙)</code></p> <p>Although <strong>XML</strong> has not replaced <strong>HTML</strong>, its unique characteristics allow it to continue to this day. . </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">优点: 1. 高度自定义[标签] 2. 不同语言中的数据流通规范 3. XML是用来描述数据的。而在HTML中,数据是写在HTML标签中的。 4. XML设计是用来描述数据的:重点是什么是数据,怎么存放数据。而HTML则是用来显示数据:重点是怎么显示数据,及怎么更好的显示数据。</pre><div class="contentsignin">Copy after login</div></div> <p>Explain XML in one sentence: <code>XML is a cross-platform, software- and hardware-independent tool for processing information (a tool for data manipulation and data transmission)</code></p> <blockquote> <p>Um.. Let me share a joke with you: </p> <p>Q: When should I use XML? </p> <p>Answer: You can write in your resume that you know XML..</p> </blockquote> <h3 id="Quick-introduction-to-XML">3. Quick introduction to XML</h3> <p>Based on the first piece of code above , let us analyze it step by step. </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><?xml version="1.0" encoding="UTF-8"?></pre><div class="contentsignin">Copy after login</div></div> <p>The first one is to declare first, declare that this XML version is <strong>1.0</strong>, and use <strong>UTF-8</strong><a href="http://www.php.cn/code/225.html" target="_blank">character set</a> to identify it . </p> <p>The following code is used for <a href="http://www.php.cn/wiki/1528.html" target="_blank">DTD</a><a href="http://www.php.cn/code/12132.html" target="_blank">constraints</a>. </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><!-- 内部 DOCTYPE 声明 定义文档是class类型文件 --> <!DOCTYPE class [ <!-- 元素class 通过类别关键字ANY声明元素,可包含任何可解析的数据组合 -->     <!ELEMENT class ANY>     <!-- 定义person元素内有四个元素 注意:约束顺序也是节点顺序 -->     <!ELEMENT person (name,time,msg,data)>     <!-- 定义name元素 为#PCDATA类型 -->     <!ELEMENT name (#PCDATA)>     <!ELEMENT time (#PCDATA)>     <!ELEMENT msg (#PCDATA)>     <!ELEMENT data (#PCDATA)> ]></pre><div class="contentsignin">Copy after login</div></div> <p> Then someone asked: </p> <p><strong>What is DTD? </strong></p> <p>Let’s take a look at the explanation on W3C: </p> <blockquote><p><strong>Document type definition (DTD) can define legal XML document building blocks. It uses a series of legal elements to define the structure of the document. </strong></p></blockquote> <p>Uh... <code>(Actually, it's just bullshit, it's the same as not saying it...)</code></p> <p>Okay, no more complaining. In fact, it sets restrictions on the XML elements, <a href="http://www.php.cn/wiki/169.html" target="_blank"> attributes</a>, etc. we write. The structure we write must follow DTD constraints. </p> <hr> <p>Let us continue to look at the following code: </p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false"><class>     <person>         <name>0x584A</name>         <time>2015年9月25日 10:24:41</time>         <msg>holle,world!</msg>         <!--这里是CDATA区间-->         <data><![CDATA[<XML的那些事...> -> 跟随0x584A、学习XML.. ]]></data>     </person> </class></pre><div class="contentsignin">Copy after login</div></div> <p>Did you find anything? </p> <p>Yes, yes, it is a tree structure. Let's take a look at the DTD constraint. The root node <strong>class</strong> is first defined, and then the <strong>person</strong> element is defined and there are four elements inside the <br><strong>person</strong> element. Elements <strong>name</strong>, <strong>time</strong>, <strong>msg</strong>, <strong>data</strong>. </p> <p>There is a strange thing among them, we call it <code>CDATA section</code>, only the text in the section will be ignored by the parser, so it <a href="http://www.php.cn/php/php-tp-sameoutput.html" target="_blank">outputs it as is</a>Special symbols<code><</code>、<code>></code>, etc...</p> <div class="code" style="position:relative; padding:0px; margin:0px;"><pre class="brush:php;toolbar:false">好了、至此关于XML的快速入门结束了,你学会了多少呢? 下一章让我们来学习XML的语法、元素及属性吧 o(∩_∩)o</pre><div class="contentsignin">Copy after login</div></div> <p>       </p>

The above is the detailed content of Quick Start Tutorial for XML. For more information, please follow other related articles on the PHP Chinese website!

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

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

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)

Can I open an XML file using PowerPoint? Can I open an XML file using PowerPoint? Feb 19, 2024 pm 09:06 PM

Can XML files be opened with PPT? XML, Extensible Markup Language (Extensible Markup Language), is a universal markup language that is widely used in data exchange and data storage. Compared with HTML, XML is more flexible and can define its own tags and data structures, making the storage and exchange of data more convenient and unified. PPT, or PowerPoint, is a software developed by Microsoft for creating presentations. It provides a comprehensive way of

Convert XML data to CSV format in Python Convert XML data to CSV format in Python Aug 11, 2023 pm 07:41 PM

Convert XML data in Python to CSV format XML (ExtensibleMarkupLanguage) is an extensible markup language commonly used for data storage and transmission. CSV (CommaSeparatedValues) is a comma-delimited text file format commonly used for data import and export. When processing data, sometimes it is necessary to convert XML data to CSV format for easy analysis and processing. Python is a powerful

Filtering and sorting XML data using Python Filtering and sorting XML data using Python Aug 07, 2023 pm 04:17 PM

Implementing filtering and sorting of XML data using Python Introduction: XML is a commonly used data exchange format that stores data in the form of tags and attributes. When processing XML data, we often need to filter and sort the data. Python provides many useful tools and libraries to process XML data. This article will introduce how to use Python to filter and sort XML data. Reading the XML file Before we begin, we need to read the XML file. Python has many XML processing libraries,

Python implements conversion between XML and JSON Python implements conversion between XML and JSON Aug 07, 2023 pm 07:10 PM

Python implements conversion between XML and JSON Introduction: In the daily development process, we often need to convert data between different formats. XML and JSON are common data exchange formats. In Python, we can use various libraries to convert between XML and JSON. This article will introduce several commonly used methods, with code examples. 1. To convert XML to JSON in Python, we can use the xml.etree.ElementTree module

Handling errors and exceptions in XML using Python Handling errors and exceptions in XML using Python Aug 08, 2023 pm 12:25 PM

Handling Errors and Exceptions in XML Using Python XML is a commonly used data format used to store and represent structured data. When we use Python to process XML, sometimes we may encounter some errors and exceptions. In this article, I will introduce how to use Python to handle errors and exceptions in XML, and provide some sample code for reference. Use try-except statement to catch XML parsing errors When we use Python to parse XML, sometimes we may encounter some

Python learning: How to install the pandas library in the system Python learning: How to install the pandas library in the system Jan 09, 2024 pm 04:42 PM

Quick Start: How to install the pandas library in Python requires specific code examples 1. Overview Python is a widely used programming language with a powerful development ecosystem that includes many practical libraries. Pandas is one of the most popular data analysis libraries. It provides efficient data structures and data analysis tools, making data processing and analysis easier. This article will introduce how to install the pandas library in Python and provide corresponding code examples. 2. Install Py

Quick Start with the Mojs Animation Library: A Guide to the Explosion Module Quick Start with the Mojs Animation Library: A Guide to the Explosion Module Sep 02, 2023 pm 11:49 PM

We start this series by learning how to animate HTML elements using mojs. In this second tutorial, we continue using the Shape module to animate built-in SVG shapes. The third tutorial covers more ways to animate SVG shapes using ShapeSwirl and the stagger module. Now we will learn how to animate different SVG shapes in bursts using the Burst module. This tutorial will depend on the concepts we introduced in the previous three tutorials. If you haven't read them yet, I recommend reading them first. Creating a Basic Burst Animation The first thing we need to do before creating any burst animation is to instantiate a Burst object. Afterwards, we can specify different properties

Python parsing special characters and escape sequences in XML Python parsing special characters and escape sequences in XML Aug 08, 2023 pm 12:46 PM

Python parses special characters and escape sequences in XML XML (eXtensibleMarkupLanguage) is a commonly used data exchange format used to transfer and store data between different systems. When processing XML files, you often encounter situations that contain special characters and escape sequences, which may cause parsing errors or misinterpretation of the data. Therefore, when parsing XML files using Python, we need to understand how to handle these special characters and escape sequences. 1. Special characters and

See all articles