d-shorkin/arrayable-xml 问题修复 & 功能扩展

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

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

d-shorkin/arrayable-xml

Composer 安装命令:

composer require d-shorkin/arrayable-xml

包简介

PHP library for parsing XML to array with laravel support

README 文档

README

PHP library for parsing XML to array. This library can formatting attributes of xml

Installation

Install via composer:

composer require d-shorkin/arrayable-xml

Usage

$xmlString = <<<XML
<root rootAttr="bar">
    <example testAttr="foo">1</example>
    <example>2</example>
</root>
XML;

$factory = new Dshorkin\ArrayableXml\ArrayableXmlFactory();
$arrayableXml = $factory->create($xmlString);

var_dump($arrayableXml->toArray());

Result:

array(2) {
  ["rootAttr"]=>
  string(3) "bar"
  ["children"]=>
  array(1) {
    ["example"]=>
    array(2) {
      [0]=>
      array(2) {
        ["testAttr"]=>
        string(3) "foo"
        ["text"]=>
        string(1) "1"
      }
      [1]=>
      array(1) {
        ["text"]=>
        string(1) "2"
      }
    }
  }
}

Laravel

If you does not use php artisan package:discover command. You need add ArrayableXmlProvider to config.

config/app.php

'providers' => [
    // ...
    
    Dshorkin\ArrayableXml\Laravel\ArrayableXmlProvider::class,
],

'aliases' => [
    // ...
    
    'ArrayableXml' => Dshorkin\\ArrayableXml\Laravel\ArrayableXml::class
]

Basic laravel usage:

ArrayableXml::create($xmlString)->toArray()

Class reference

Dshorkin\ArrayableXml\ArrayableXmlFactory

Create

ArrayableXmlFactory::create(string $str, [string $childrenFieldKey, [string $textFieldKey, [bool $miniElements]]]): ArrayableXmlInterface
Param Type Default Description
str string XML string
childrenFieldKey string children Parse child nodes in children property, if you send empty string child nodes will be merge with attributes
textFieldKey string text Text content will be parse in property with this key
miniElements bool true If you disable it all elements will be return array of children. By default if parent has single child that will be returned alone

Create From SimpleXmlElement

ArrayableXmlFactory::createFromSimpleXmlElement(\SimpleXMLElement $xml, [string $childrenFieldKey, [string $textFieldKey, [bool $miniElements]]]): ArrayableXmlInterface

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固