ermst4r/xml2readablearray 问题修复 & 功能扩展

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

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

ermst4r/xml2readablearray

Composer 安装命令:

composer require ermst4r/xml2readablearray

包简介

Convert xml to an array string (node1.node2.node3), so you can retrieve them via an multidimensional array by splitting the string.

README 文档

README

Convert xml to an array string and parse the nodes without any effort.

Real life scenario

You have an xml file, but you don't want to write a parser for every xml file. What can you do? Install this package :)

Example

We want to parse this XML file.

<?xml version="1.0" encoding="utf-8"?>
<root>
    <items>


    <node>I am</node>
    <node1>a</node1>
    <node2 id="1337">1337 h4xor</node2>
    </items>
</root>

1. Open the xml file

$n = new \Ermst4r\Xml\XmlReaderFacade('feed.xml');

2. Show the mapping for this xml file

We can now view the xml nodes in string format. If you run this code:

print_r($n->showXmlMapping());

We see something like this:

Array ( [0] => items.node [1] => items.node1 [2] => items.node2 [3] => items.node2.id )

3. Parsing

Now if we loop through the xml nodes, we can parse the items. Lets say i only want node2 and the id of node2... We simply pass an array of the array node names. See example below.

PS. Remember, we can get the items from the showXmlMapping() method ;-)...

while($node = $n->streamingNode()) {

    var_dump($n->XmlArrayToValuesFacade(['items.node2','items.node2.id'],$node));
    
}

And voila we get the value of the xml. (only items which are !is_array() will be parsed)

Of if you want to parse all the items you can do this:

while($node = $n->streamingNode()) {

    var_dump($n->XmlArrayToValuesFacade($n->showXmlMapping(),$node));
    
}

4. Advanced

We can even parse complicated xml files with nested nodes and attributes.. The principle stays the same like step 1,2,3.

Credits

I hope this package can help you with parsing xml files. This package is also used in my opensource project http://www.dfbuilder.com Dfbuilder is a opensource tool what export files to different formats.

With love...

Erwin Nandpersad

http://www.ermmedia.nl

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL
  • 更新时间: 2017-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固