定制 php-xml/large-text-node 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

php-xml/large-text-node

Composer 安装命令:

composer require php-xml/large-text-node

包简介

Handling large text nodes requires using low-end PHP API functions. This package provides a simple interface to write large text nodes to a resource so that memory usage is reduced to a minimum.

README 文档

README

The more high end XML APIs of PHP (e.g. SimpleXML) have the disadvantage that they store the whole XML document in memory. Parsing large XML files is therefore not the easiest task.

This package is designed to read large text nodes in a memory friendly fashion, so that for instance base64 encoded files saved in XML text nodes can be written to a file.

Selecting text nodes

To read the contents of a text node, a path must be provided. To keep things simple, a path is just a list of tag names separated by a forward slash /. Currently only the first match in the XML document is returned.

For instance, the path "document/tag/name" would match the I am matched text node.

<document>
    <tag>
        <name>I am matched</name>
    </tag>
    <tag>
        <name>I am skipped</name>
    </tag>
</document>

Examples

To give you an idea, see the following examples

Reading a large XML file

<?php
// php://temp writes first to memory, but if the text node is large, a temporary file is used on the fly.
$output = fopen('php://temp', 'w+');
$input = fopen('some-large-file.xml', 'r');
$path = 'some/target';

// Use the resource reader to parse the XML document
try {
    $reader = new StreamReader($input, $path, $output);
    $reader->parse();
    rewind($output);
    // Maybe do something with $output
} catch (XMLException $e) {
    // Whoops
} finally {
    fclose($output);
    fclose($input);
}

Converting a base64 encoded text node to a file

// Assume $input is some given stream
$input = fopen('some-file');
$path = 'some/target';

// Open an output stream and add PHP's own base64 decoder filter
$output = fopen('php://temp', 'w+');
stream_filter_append($output, 'convert.base64-decode');

try {
    $reader = new StreamReader($input, $path, $output);
    $reader->parse();
    rewind($output);
} catch (XMLException $e) {
    // Whoops
} finally {
    fclose($output);
    fclose($input);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-07-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固