mindplay/easyxml 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mindplay/easyxml

最新稳定版本:1.0.1

Composer 安装命令:

composer require mindplay/easyxml

包简介

XML parser with a functional approach

README 文档

README

Build Status

Scrutinizer Code Quality

Code Coverage

Functional XML-reader for PHP 5.3+.

A somewhat different approach to reading/parsing XML files with PHP, using a hierarchy of anonymous functions (closures) reflecting the hierarchy of the XML document itself.

This is useful when reading structured XML documents - e.g. XML documents with a predictable structure. It's probably less than enjoyable when reading unstructured documents, such as XHTML documents.

Parsing happens on-the-fly, e.g. avoiding the overhead of loading an entire document into memory and performing repetitive queries against it. This approach is memory efficient, enabling you to parse very large documents in a streaming fashion - it is not super fast (throughput ~500 KB/sec on my laptop) but XML parsing is never truly fast, so you should definitely always cache the parsed results.

Usage

Let's say you wish to read the following XML file:

<?xml version="1.0" encoding="UTF-8"?>
<cats>
    <cat name="whiskers">
        <kitten name="mittens"/>
    </cat>
    <cat name="tinker">
        <kitten name="binky"/>
    </cat>
</cats>

Your reader might look something like this:

$doc = new Parser();

$doc['cats/cat'] = function (Visitor $cat, $name) {
    echo "a cat named: {$name}\n";

    $cat['kitten'] = function ($name) {
        echo "a kitten named: {$name}\n";
    };
};

$doc->parseFile('my_cats.xml');

The output would be this:

a cat named: whiskers
a kitten named: mittens
a cat named: tinker
a kitten named: binky

If it's not obvious, the path cats/cat designates a <cat> node inside a <cats> node.

You can also match text-nodes, e.g. a path like foo/bar#text will match YO in <foo><bar>YO</bar></foo>.

And finally, you can use #end to match closing tags, if needed.

Incidentally, I don't actually have cats - but if I did, you can bet those would be their names.

See "test.php" and "example/cd_catalog.php" for more examples of how to use this.

统计信息

  • 总下载量: 2.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2014-11-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固