Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/byjg/php-anydataset-xml

Anydataset Xml abstraction. Anydataset is an agnostic data source abstraction layer in PHP
https://github.com/byjg/php-anydataset-xml

anydataset php xml xml-anydataset xml-parsing

Last synced: 2 months ago
JSON representation

Anydataset Xml abstraction. Anydataset is an agnostic data source abstraction layer in PHP

Awesome Lists containing this project

README

        

# AnyDataset-Xml

[![Build Status](https://github.com/byjg/php-anydataset-xml/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-anydataset-xml/actions/workflows/phpunit.yml)
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-anydataset-xml/)
[![GitHub license](https://img.shields.io/github/license/byjg/php-anydataset-xml.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/php-anydataset-xml.svg)](https://github.com/byjg/php-anydataset-xml/releases/)

XML abstraction dataset. Anydataset is an agnostic data source abstraction layer in PHP.

See more about Anydataset [here](https://opensource.byjg.com/php/anydataset).

## Examples

### Simple Manipulation

example1.xml
```xml


Everyday Italian
Giada De Laurentiis
2005
30.00


Harry Potter
J K. Rowling
2005
29.99


Learning XML
Erik T. Ray
2003
39.95

```

example1.php
```php
"@category",
"title" => "title",
"lang" => "title/@lang",
"lang2" => function ($row) {
return substr($row->get('lang'), 0, 2);
}
] // Mapping columns
);

$iterator = $dataset->getIterator();
foreach ($iterator as $row) {
echo $row->get('category'); // Print COOKING, CHILDREN, WEB
echo $row->get('title'); // Print Everyday Italian, Harry Potter, Learning Xml
echo $row->get('lang'); // Print en-US, de-DE, pt-BR
echo $row->get('lang2'); // Print en, de, pt
}
```

### Xml with namespaces

example2.xml
```xml

myId
2014-09-15T19:35:55.795Z

Title







My Name
My Email

Contacts
2107
1
20

http://www.google.com/m8/feeds/contacts/my%40gmail.com/base/0
2013-10-05T22:16:03.564Z

Person 1







http://www.google.com/m8/feeds/contacts/my%40gmail.com/base/1
2012-07-12T17:19:17.546Z

Person 2






```

example2.php
```php
"http://www.w3.org/2005/Atom",
"gd" => "http://schemas.google.com/g/2005"
);

$rootNode = 'fake:entry';
$colNode = array("id" => "fake:id", "updated" => "fake:updated", "name" => "fake:title", "email" => "gd:email/@address");
$xmlDataset = new \ByJG\AnyDataset\Xml\XmlDataset(
$xml,
$rootNode,
$colNode,
$namespace
);
$xmlIterator = $xmlDataset->getIterator();
```

## Install

```
composer require "byjg/anydataset-xml"
```

## Running the Unit tests

```bash
vendor/bin/phpunit
```

## Dependencies

```mermaid
flowchart TD
byjg/anydataset-xml --> byjg/anydataset
byjg/anydataset-xml --> byjg/xmlutil
byjg/anydataset-xml --> ext-dom
```
----
[Open source ByJG](http://opensource.byjg.com)