PHP code example of dominservice / onix-parser

1. Go to this page and download the library: Download dominservice/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/ */

    

dominservice / 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();

// Either get the Code object and read it's code and/or value
$type = $product->getNotificationType();
$code = $code->getCode();   // "03"
$value = $code->getValue(); // "Notification confirmed on publication"

// or directly get the value as string
$value = (string) $product->getNotificationType();

// Create parser using german code list values
$parser = new \Dso\Onix\Parser('de');

// get the DescriptiveDetail portion of the product
$descriptiveDetail = $product->getDescriptiveDetail();

foreach ($descriptiveDetail->getMeasures() as $measure) {
	echo sprintf('%s: %s %s',                      // -> "Height: 210 Centimeters"
		(string) $measure->getMeasureType(),       // e.g. "Height"
		$measure->getMeasurement(),                // e.g. "210"
		(string) $measure->getMeasureUnitCode()    // e.g. "Centimeters"
	);
}

/** @var Dso\Onix\Product\Measure */
$height = $descriptiveDetail->getHeight();
$width = $descriptiveDetail->getWidth();
$thickness = $descriptiveDetail->getThickness();
$weight = $descriptiveDetail->getWeight();

echo sprintf("Height: %s %s", $height->getMeasurement(), $height->getMeasureUnitCode()->getCode());
// --> Height: 210 cm
xml
<ONIXMessage>
    <Product>
        <NotificationType>03</NotificationType>
        [...]
    </Product>
</ONIXMessage>