ramlev / dom-onix-parser
An ONIX 3.0 Parser
Requires
- php: >=8.3
- symfony/property-access: ^7.4
- symfony/property-info: ^7.4
- symfony/serializer: ^7.4
Requires (Dev)
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2026-03-23 10:56:56 UTC
README
A PHP library for reading ONIX 3.0 files in both Short and Ref tag formats. Text elements in different formats and ONIX date formats are automatically parsed. Code list values are resolved to human-readable strings.
This library is under active development. Most fields are detected and parsed, but some still need work.
Requirements
- PHP >= 8.3
- Symfony Serializer ^7.4
Installation
composer require ramlev/dom-onix-parser
Usage
$parser = new \Dso\Onix\Parser(); /** @var \Dso\Onix\Message\Message */ $message = $parser->parseString(file_get_contents('sample.xml')); /** @var \Dso\Onix\Product\Product[] */ $products = $message->getProducts();
Code Lists
All code lists from issue 61 are included. Codes in the ONIX file are automatically resolved to their human-readable values.
<Product> <NotificationType>03</NotificationType> </Product>
$type = $product->getNotificationType(); $type->getCode(); // "03" $type->getValue(); // "Notification confirmed on publication" (string) $type; // "Notification confirmed on publication"
Multi-Language Code Lists
Pass a language code to the parser constructor to get code list values in that language:
$parser = new \Dso\Onix\Parser('de');
| Language | Code |
|---|---|
| English (default) | en |
| Spanish | es |
| German | de |
| French | fr |
| Italian | it |
| Norwegian | nb |
| Turkish | tr |
Code lists were scraped from the EDITEUR website. Some translations may be incomplete or inaccurate — pull requests are welcome.
Text Content
Text fields are returned as Text objects and support multiple ONIX text formats (plain, HTML, XHTML, XML):
$text = $textContent->getText(); (string) $text; // raw content $text->toPlain(); // strips HTML tags, converts <br> to newlines $text->toHtml(); // returns HTML; wraps plain text in <p> tags
Dates
Date fields are returned as Date objects and support all ONIX date format codes (CodeList 55), including ranges, weeks, quarters and seasons:
$date = $publishingDate->getDate(); $date->format('Y-m-d'); // e.g. "2024-03-15" $date->format('d. F Y'); // e.g. "15. March 2024"
Measurements
$detail = $product->getDescriptiveDetail(); // Loop all measures foreach ($detail->getMeasures() as $measure) { echo sprintf('%s: %s %s', (string) $measure->getMeasureType(), // e.g. "Height" $measure->getMeasurement(), // e.g. "210" (string) $measure->getMeasureUnitCode() // e.g. "Centimeters" ); } // Shorthand helpers $detail->getHeight(); $detail->getWidth(); $detail->getThickness(); $detail->getWeight();
Running Tests
composer test
Built With
License
MIT — see LICENSE.