PHP SimpleXML
与 DOM 或 Expat 解析器相比,SimpleXML 仅仅用几行代码就可以从元素中读取文本数据。
SimpleXML 可把 XML 文档转换为对象,比如:
元素 - 被转换为 SimpleXMLElement 对象的单一属性。当同一级别上存在多个元素时,它们会被置于数组中。
属性 - 通过使用关联数组进行访问,其中的下标对应属性名称。
元素数据 - 来自元素的文本数据被转换为字符串。如果一个元素拥有多个文本节点,则按照它们被找到的顺序进行排列。
当执行类似下列的基础任务时,SimpleXML 使用起来非常快捷:
读取 XML 文件
从 XML 字符串中提取数据
编辑文本节点或属性
不过,在处理高级 XML 时,比如命名空间,最好使用 Expat 解析器或 XML DOM。
SimpleXML 函数是 PHP 核心的组成部分。无需安装就可以使用这些函数。
XML 文件:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Reminder</heading> <body>Don't forget the meeting!</body> </note>
<?php $xml = simplexml_load_file("test.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } ?>

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

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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