search
HomeBackend DevelopmentPHP TutorialAbout the PHP toolkit expat parsing XML_PHP tutorial
About the PHP toolkit expat parsing XML_PHP tutorialJul 15, 2016 pm 01:27 PM
phpxmlmainintroduceaboutFunctiondevelopToolkitpowerfulRevealarticleofparsealong with

As PHP develops, its functions are also becoming more powerful. The introduction of this article mainly introduces the functions of the PHP toolkit. I hope it can be helpful to everyone. Everyone these days is touting XML as a Web developer's best friend, making it easy to format and display data from almost any data source. However, well-formatted data is far from ideal for dynamic content. Most web developers will tell you how the web today can work without dynamic content! The question is: "How to create dynamic content using XML?"

The answer is to use a dynamic content processing language to parse XML, such as PHP or Perl, etc. , Theoretically, this type of programming language can utilize XML for various purposes. It's nothing more than using some toolkits that can parse XML. James Clark provides a toolkit called expat. The expat XML toolkit uses C language to parse XML, making it easy for PHP and XML to dance together. PHP is a great scripting language designed specifically for the web. XML is a standard for representing web content. How beautiful it would be if the two joined forces!

Below I will show readers a simple example. This example can illustrate how to use the PHP toolkit to parse XML documents into HTML. Then I'll introduce some other XML concepts of PHP. Parsing XML with the PHP toolkit is simple and intuitive but requires some explanation of the details. Once you really get the hang of it, you'll be surprised why you didn't think of combining them earlier.

Overview

PHP uses expat, an XML toolkit, to parse XML through C language. The function set of this toolkit is the same as that used by Perl XML parsing. In addition, this toolkit is an event-driven parser. That is to say, expat treats each XML tag or new line of code as the start of an event, and the event is the trigger of the function. Installing Expat is very simple, and if you are using the Apache web server, you can find installation and download instructions on the PHP XML reference page.

The basic task of parsing XML with PHP is this: First, create an instance of the XML parser. Next, define functions that handle trigger events, such as start or end tags. Subsequently, define the actual data processing procedures. Finally, the XML file is opened, the file data is read and the data is parsed. Afterwards closing the file releases the XML parser.

Look, like I said, there’s nothing special about this process. However, before we discuss specific examples, here are some caveats: Expat does not perform XML validation. This means that as long as the XML file is well-formed - all elements are nested properly, opening and closing tags have no errors - it will be parsed. Expat does not care whether the XML conforms to the standards or definitions referenced in the XML file header. Expat converts all XML tags to uppercase letters. Be careful if your script mixes uppercase and lowercase letters in tag names and other content. PHP is compiled with the magic quotes setting enabled, so complex XML files will not be parsed correctly. If magic quotes is not the default setting, just pretend I didn't say it.

Basic Example

In order to simplify complex things, I have omitted error checking and other unnecessary things in the example. Of course, you can do it yourself The code is whatever you want. I assume that you are already familiar with PHP and its syntax, and I will explain the XML functions. First I'll explain what a script is, and then I'll define user-defined functions that actually precede the code that references them. Related Attachment: Program Listing A shows the complete code of the script, and the XML document to be parsed by the script is Related Attachment: Program Listing B. The output results after processing are shown in Table A.

<ol class="dp-xml">
<li class="alt"><span><span>XML Articles  </span></span></li>
<li class=""><span>"Remedial XML for programmers: Basic syntax"              </span></li>
<li class="alt"><span>In this first installment in a three-part series,   </span></li>
<li class=""><span>I'll introduce you to XML and its basic syntax.  </span></li>
<li class="alt"><span>"Remedial XML: Enforcing document formats with DTDs"              </span></li>
<li class=""><span>To enforce structure requirements for an XML document, you have to turn to one of XML's attendant technologies, data type definition (DTD).  </span></li>
<li class="alt"><span>"Remedial XML: Using XML Schema"              </span></li>
<li class=""><span>In this article, we'll briefly touch on the shortcomings of DTDs and discuss the basics of a newer, more powerful standard: XML Schemas.  </span></li>
<li class="alt"><span>"Remedial XML: Say hello to DOM"              </span></li>
<li class=""><span>Now it's time to put on your programmer's hat and get acquainted with Document Object Model (DOM),   </span></li>
<li class="alt"><span>which provides easy access to XML documents via a tree-like set of objects.  </span></li>
<li class=""><span>"Remedial XML: Learning to play SAX"              </span></li>
<li class="alt"><span>In this fifth installment in our Remedial XML series, I'll introduce you to the SAX API and provide some links to <br>SAX implementations in several languages. </span></li>
</ol>



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/446502.htmlTechArticleWith the development of PHP, its functions are also becoming more powerful. The introduction of this article mainly introduces the functions of PHP toolkit. I hope it can be useful to everyone. Bring help. Nowadays, everyone advocates that XML is the best friend of web developers. With...
Statement
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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么查找字符串是第几位php怎么查找字符串是第几位Apr 22, 2022 pm 06:48 PM

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。

See all articles

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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version