decodelabs/exemplar
最新稳定版本:v0.5.11
Composer 安装命令:
composer require decodelabs/exemplar
包简介
Powerful XML tools
README 文档
README
Powerful XML tools for PHP.
Exemplar provides a set of exhaustive and intuitive interfaces for reading, writing and manipulating XML documents and fragments.
Installation
This package requires PHP 8.4 or higher.
Install via Composer:
composer require decodelabs/exemplar
Usage
Reading & manipulating
Access and manipulate XML files with a consolidated interface wrapping the DOM functionality available in PHP:
use DecodeLabs\Exemplar\Element as XmlElement; $element = XmlElement::fromFile('/path/to/my/file.xml'); if($element->hasAttribute('old')) { $element->removeAttribute('old'); } $element->setAttribute('new', 'value'); foreach($element->scanChildrenOfType('section') as $sectTag) { $inner = $sectTag->getFirstChildOfType('title'); $sectTag->removeChild($inner); // Flatten to plain text echo $sectTag->getComposedTextContent(); } file_put_contents('newfile.xml', (string)$element);
See Element.php for the full interface.
Writing
Programatically generate XML output with a full-featured wrapper around PHP's XML Writer:
use DecodeLabs\Exemplar\Writer as XmlWriter; $writer = new XmlWriter(); $writer->writeHeader(); $writer->{'ns:section[ns:attr1=value].test'}(function ($writer) { $writer->{'title#main'}('This is a title'); $writer->{'@body'}('This is an element with content wrapped in CDATA tags.'); $writer->writeCData('This is plain CDATA'); }); echo $writer;
This creates:
<?xml version="1.0" encoding="UTF-8"?> <ns:section ns:attr1="value" class="test"> <title id="main">This is a title</title> <body><![CDATA[This is an element with content wrapped in CDATA tags.]]></body> <![CDATA[This is plain CDATA]]></ns:section>
See Writer.php for the full interface.
Licensing
Exemplar is licensed under the MIT License. See LICENSE for the full license text.
统计信息
- 总下载量: 1.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-31