Download the PHP package eliashaeussler/valinor-xml without Composer
On this page you can find all versions of the php package eliashaeussler/valinor-xml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download eliashaeussler/valinor-xml
More information about eliashaeussler/valinor-xml
Files in eliashaeussler/valinor-xml
Package valinor-xml
Short Description XML source for cuyz/valinor
License GPL-3.0-or-later
Informations about the package valinor-xml
A Composer library that provides an additional XML source for use with
the popular cuyz/valinor library.
This allows to easily map XML files or contents to any signature supported
by Valinor, e.g. objects or special array shapes. It leverages the
mtownsend/xml-to-array
library to convert raw XML to a reusable array structure.
🔥 Installation
⚡ Usage
Given the following XML:
These are the resulting classes:
Mapping from XML string
In order to map the given XML to the Person class, you need
to follow these three steps:
- Create a new mapper as written in Valinor's documentation
- Parse and prepare your XML using the shipped
XmlSource - Use the mapper to map your XML to the
Personclass
The resulting object will look something like this:
Mapping from XML file
The XML can also be read from an external file:
Convert nodes to collections
Sometimes it might be necessary to always convert XML nodes to collections. Given the following XML:
Let's assume you want to map this XML to the following class:
You will recognize that this does not work as expected when using the above mapping method:
It will instead throw an exception like this:
This is because the XML converter does not know whether <member> should
be a collection or if it's just a "normal" node. That's why the XmlSource
provides an appropriate method to convert such nodes to collections:
The resulting object will look something like this:
However, this is only relevant if only one node of the collection exists in your XML. If the XML contains more than one node, the XML converter properly converts them to a collection:
🧑💻 Contributing
Please have a look at CONTRIBUTING.md.
⭐ License
This project is licensed under GNU General Public License 3.0 (or later).
All versions of valinor-xml with dependencies
ext-mbstring Version *
cuyz/valinor Version ^1.3 || ^2.0
mtownsend/xml-to-array Version ^2.0