8fold/php-xml-builder
Composer 安装命令:
composer require 8fold/php-xml-builder
包简介
A library for building XML document and element strings.
README 文档
README
XML Builder is designed to build a string, not a document object model (DOM)
or abstract syntax tree (AST).
For DOM or AST, there are other libraries and native implementations (ex. PHP:DOM and SimpleXML).
You might use XML Builder to generate a string you feed into either PHP:DOM or Simple XML. Or, use the string as the body of an HTTP response.
Use the Element class to create individual nodes within the document.
Use the Document class to generate the doctype declaration and root level element.
Installation
composer require 8fold/php-xml-builder
Usage
Warning: Users of this library are responsible for sanitizing content.
use Eightfold\XMLBuilder\Document; use Eightfold\XMLBuilder\Element; use Eightfold\XMLBuilder\Cdata; echo Document::create('root', Element::create('child', Element::create('grandchild')->omitEndTag()->props('name Xavier'), Cdata::create('Hello, my name is Xavier!') ) );
Output:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <root><child><grandchild name="Xavier"/><![CDATA[Hello, my name is Xavier!]]></child></root>
Output (formatted):
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <root> <child> <grandchild name="Xavier"/> <![CDATA[Hello, my name is Xavier!]]> </child> </root>
Alternatively, there is a shorthand variation.
The shorthand method uses the __callStatic PHP magic method.
use Eightfold\XMLBuilder\Document; use Eightfold\XMLBuilder\Element; use Eightfold\XMLBuilder\Cdata; echo Document::root( Element::child( Element::grandchild()->omitEndTag()->props('name Xavier'), Cdata::create('Hello, my name is Xavier!') ) ); // output: Same as previous example.
Comments are available:
use Eightfold\XMLBuilder\Document; use Eightfold\XMLBuilder\Element; use Eightfold\XMLBuilder\Cdata; echo Document::create( 'root', Comment::create('comment'), Element::create('tag')->omitEndTag() );
Output (unformatted):
<?xml version = "1.0" encoding = "UTF-8" standalone = "yes" ?> <root> <!-- comment --> <tag /></root>
Compatibility
| XML Builder version | PHP version |
|---|---|
| 1+ | 8.0+ |
| 0+ | 7.4+ |
Details
The origins of this library was an experiment where PHP was viewed as a "pure" programming language, not a template engine that grew into being a language.
The primary pain point was to maintain the feel of writing human-readable XML (tabs and spaces) while reducing the risk of human error; specifically, mismatched beginning and end tags.
The secondary pain point was that PHP:DOM and SimpleXML felt cumbersome when generating XML and HTML documents.
Other
8fold/php-xml-builder 适用场景与选型建议
8fold/php-xml-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 10 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 8fold/php-xml-builder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 8fold/php-xml-builder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 14k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 4
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-04