PHP code example of ramlev / dom-onix-parser
1. Go to this page and download the library: Download ramlev/dom-onix-parser library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ramlev / dom-onix-parser example snippets
$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();
$type = $product->getNotificationType();
$type->getCode(); // "03"
$type->getValue(); // "Notification confirmed on publication"
(string) $type; // "Notification confirmed on publication"
$parser = new \Dso\Onix\Parser('de');
$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
$date = $publishingDate->getDate();
$date->format('Y-m-d'); // e.g. "2024-03-15"
$date->format('d. F Y'); // e.g. "15. March 2024"
$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();