定制 zacksitt/xml-helper 二次开发

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

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

zacksitt/xml-helper

最新稳定版本:v1.0.0

Composer 安装命令:

composer require zacksitt/xml-helper

包简介

???The Laravel XML Helper package simplifies XML data handling within Laravel applications. Easily parse, generate, and transform XML with intuitive methods that integrate seamlessly with Laravel's ecosystem.

README 文档

README

The Laravel XML Helper package provides an easy and efficient way to work with XML data in your Laravel applications. It includes methods for converting arrays to XML, parsing XML to arrays, and extracting values using XPath queries.

Installation

To install the package, you can use Composer:

composer require zacksitt/xml-helper

Usage
Converting Arrays to XML
Use the toXML() method to convert a PHP array to an XML string.

use Zacksitt\XmlHelper\XmlHelper;

$array = [
    'root' => [
        'element' => 'value',
        'anotherElement' => 'anotherValue'
    ]
];

$xmlHelper = new XmlHelper();
$xmlString = $xmlHelper->toXml($array);

echo $xmlString;

Parsing XML to Arrays

The toArray() method parses an XML string into a PHP array.

$xmlString = '<root><element>value</element><anotherElement>anotherValue</anotherElement></root>';
$xmlHelper = new XmlHelper();
$array = xmlHelper->toArray($xmlString);

print_r($array);

Extracting Values with element.
Use the getValue() method to extract values from an XML string using an element name.

$xmlString = '<root><element>value</element><anotherElement>anotherValue</anotherElement></root>';
$xpath = 'anotherElement';

$xmlHelper = new XmlHelper();
$value = $xmlHelper->getValue($xmlString, $xpath);

echo $value; // Output: anotherValue

Methods
toXML(array $data): string
Converts a PHP array to an XML string.

toArray(string $xml): array
Parses an XML string into a PHP array.

getValue(string $xml, string $element): mixed
Extracts a value from an XML string using an XPath query.

License
This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-06