dev-master
9999999-devA package that transforms XML/JSON documents from one standard to another
MIT
The Requires
- php >=5.5.9
- symfony/yaml ^3.0
The Development Requires
by Brian Seitel
A package that transforms XML/JSON documents from one standard to another
A translator for XML/JSON files using a YAML or JSON configuration., (*1)
In the Discworld series by Larry Niven, the Librarian is a wizard turned into an orangutan early in the series. He understands Morporkian (English) perfectly well, but always speaks in orangutan, using words like "Ook" and "Eek". Most human characters have little trouble understanding this, but every now and again someone unfamiliar with the Librarian meets him and cannot quite figure out what that particular "Ook" meant. The Librarian tried to address this issue by writing an Orangutan-Morpokian dictionary, but has not progressed beyond "Ook" yet., (*2)
Yeah, pretty funny, right?, (*3)
Ook utilizes the "dot" notation when defining rules for translating between arrays. Here's a quick example of what dot notation is:, (*4)
$array = ['items' => [ 'item' => [ ['name' => 'computer', 'price' => 1000], ['name' => 'monitor', 'price' => 150] ] ]; Arr::get('items.item.0.price') // 1000
We'll use the same thing to define a ruleset for XML:, (*5)
<items> <item> <name>computer</name> <price>1000</price> </item> <item> <name>monitor</name> <price>150</price> </item> </items>
Ook will convert this to an array with a key of item.price
. Let's imagine we want to translate this from item.price
to inventory.item.price
, (*6)
inventory.item.*.name: items.item.*.name inventory.item.*.price: items.item.*.price
To translate it, we simply run:, (*7)
$librarian = new Ook\Librarian('sample.xml', 'config.yaml'); $output = $librarian->transform();
This will return:, (*8)
Array ( [inventory] => Array ( [item] => Array ( [0] => Array ( [name] => computer [price] => 1000 ) [1] => Array ( [name] => monitor [price] => 150 ) ) ) )
Check out the /examples
directory for more samples., (*9)
A package that transforms XML/JSON documents from one standard to another
MIT