Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fawno/simplexmlextended
SimpleXMLElement Extended class
https://github.com/fawno/simplexmlextended
php simplexmlelement xml
Last synced: about 5 hours ago
JSON representation
SimpleXMLElement Extended class
- Host: GitHub
- URL: https://github.com/fawno/simplexmlextended
- Owner: fawno
- License: mit
- Created: 2019-12-15T08:03:34.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-07-21T17:29:06.000Z (4 months ago)
- Last Synced: 2024-09-22T20:18:05.575Z (about 2 months ago)
- Topics: php, simplexmlelement, xml
- Language: PHP
- Size: 27.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleXMLExtended
[![GitHub license](https://img.shields.io/github/license/fawno/SimpleXMLExtended)](https://github.com/fawno/SimpleXMLExtended/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/fawno/SimpleXMLExtended)](https://github.com/fawno/SimpleXMLExtended/releases)
[![Packagist](https://img.shields.io/packagist/v/fawno/simple-xml-extended)](https://packagist.org/packages/fawno/simple-xml-extended)
[![Packagist Downloads](https://img.shields.io/packagist/dt/fawno/simple-xml-extended)](https://packagist.org/packages/fawno/simple-xml-extended/stats)
[![GitHub issues](https://img.shields.io/github/issues/fawno/SimpleXMLExtended)](https://github.com/fawno/simple-xml-extended/issues)
[![GitHub forks](https://img.shields.io/github/forks/fawno/SimpleXMLExtended)](https://github.com/fawno/simple-xml-extended/network)
[![GitHub stars](https://img.shields.io/github/stars/fawno/SimpleXMLExtended)](https://github.com/fawno/simple-xml-extended/stargazers)
[![PHP](https://img.shields.io/packagist/php-v/fawno/simple-xml-extended)](https://php.net)SimpleXMLElement Extended class
SimpleXMLExtended add a new method for create CData nodes.
Also added a new method for output e nice format XML.## Requirements
- libxml PHP extension (enabled by default).
- SimpleXML PHP extension (enabled by default).
- DOM PHP extension (enabled by default).## Installation
You can install this plugin into your application using
[composer](https://getcomposer.org):```
composer require fawno/simple-xml-extended
```or, clone/download this repo, and include src/SimpleXMLExtended.php in your project.
## Usage
```php
use Fawno\SimpleXMLExtended\SimpleXMLExtended;// Get a SimpleXMLExtended object from a DOM node
$xml = simplexml_import_dom($dom, SimpleXMLExtended::class);// Interprets an XML file into an SimpleXMLExtended object
$xml = simplexml_load_file($xml_file, SimpleXMLExtended::class);// Interprets a string of XML into an SimpleXMLExtended object
$xml = simplexml_load_string($xml_string, SimpleXMLExtended::class);// Creates a new SimpleXMLExtended object
$xml = new SimpleXMLExtended($xml_string);// Adds a child element to the XML node as cdata
$xml->addChildCData('node_cdata', 'data as cdata');// Return a well-formed and nice formated XML string based on SimpleXMLExtended element
$xml->formatXML()
```## Example
```php
require 'src/SimpleXMLExtended.php';use Fawno\SimpleXMLExtended\SimpleXMLExtended;
$root = new SimpleXMLExtended('');
$root->addChildCData('node_cdata', 'data as cdata');
print_r($root->asXML());
/*
Output:
*/print_r($root->formatXML());
/*
Output:
*/
```