Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thenorthmemory/xml
A wrapper of the XML parser and builder
https://github.com/thenorthmemory/xml
Last synced: about 2 months ago
JSON representation
A wrapper of the XML parser and builder
- Host: GitHub
- URL: https://github.com/thenorthmemory/xml
- Owner: TheNorthMemory
- License: apache-2.0
- Created: 2022-09-25T08:06:55.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-08T09:50:50.000Z (4 months ago)
- Last Synced: 2024-10-08T20:54:32.024Z (3 months ago)
- Language: PHP
- Size: 51.8 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A wrapper of the XML parser and builder
Split from the wechatpay-php project for general usages.
[![GitHub actions](https://github.com/TheNorthMemory/xml/workflows/CI/badge.svg)](https://github.com/TheNorthMemory/xml/actions)
[![Packagist Stars](https://img.shields.io/packagist/stars/thenorthmemory/xml)](https://packagist.org/packages/thenorthmemory/xml)
[![Packagist Downloads](https://img.shields.io/packagist/dm/thenorthmemory/xml)](https://packagist.org/packages/thenorthmemory/xml)
[![Packagist Version](https://img.shields.io/packagist/v/thenorthmemory/xml)](https://packagist.org/packages/thenorthmemory/xml)
[![Packagist PHP Version Support](https://img.shields.io/packagist/php-v/thenorthmemory/xml)](https://packagist.org/packages/thenorthmemory/xml)
[![Packagist License](https://img.shields.io/packagist/l/thenorthmemory/xml)](https://packagist.org/packages/thenorthmemory/xml)## Install
```shell
composer require thenorthmemory/xml
```## Usage
```php
use TheNorthMemory\Xml\Transformer;
$array = Transformer::toArray('world');
// print_r($array);
// Array
// (
// [hello] => world
// )
$xml = Transformer::toXml($array);
// print_r($xml);
// world
$xml = <<t146d70eb241c44c63b6efc1cc93ccfc5d
t12a74d11687d444deba8a6cc52051ac27TencentCOSRequest;
$array = Transformer::toArray($xml);
// Array
// (
// [Operation] => Array
// (
// [WatermarkTemplateId] => Array
// (
// [0] => t146d70eb241c44c63b6efc1cc93ccfc5d
// [1] => t12a74d11687d444deba8a6cc52051ac27
// )// )
// )
$xml1 = Transformer::toXml($array, true, true, 'Request');
// print_r($xml1);
//
//
//
// t146d70eb241c44c63b6efc1cc93ccfc5d
// t12a74d11687d444deba8a6cc52051ac27
//
//
//
$array['Operation']['WatermarkTemplateId'] = Transformer::wrap($array['Operation']['WatermarkTemplateId'], true, 'WatermarkTemplateId');
$xml2 = Transformer::toXml($array, true, true, 'Request');
// print_r($xml2);
//
//
// t146d70eb241c44c63b6efc1cc93ccfc5d
// t12a74d11687d444deba8a6cc52051ac27
//
//
```## API
**`Transformer::toArray(string $xml = '')`**
Parse the XML `string` to `array`.
**`Transformer::sanitize(string $xml = '')`**
Sanitize the XML `string` in the [XML1.0 20081126 Character Range](https://www.w3.org/TR/2008/REC-xml-20081126/#charsets).
**`Transformer::toXml(array $data, bool $headless = true, bool $indent = false, string $root = 'xml', string $item = 'item'): string`**
Build the data `array` to XML `string`.
**`Transformer::wrap(array $data, bool $wrapped = false, string $label = 'item'): LabeledArrayIterator`**
Wrap the `array` data with a `label` and `wrapped` flag.
## License
[Apache-2.0 License](LICENSE)