PHP code example of netlogix / xml-processor

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

    

netlogix / xml-processor example snippets


use Netlogix\XmlProcessor\NodeProcessor\AbstractNodeProcessor;
use Netlogix\XmlProcessor\NodeProcessor\OpenNodeProcessorInterface;
use Netlogix\XmlProcessor\NodeProcessor\Context\OpenContext;

class OpenValueNodeProcessor extends AbstractNodeProcessor implements OpenNodeProcessorInterface
{
    const NODE_PATH = 'value';
    private $nodeValues = [];

    public function openElement(OpenContext $context)
    {
        $xml = $context->getXmlProcessorContext()->getXmlReader();
        $node = $xml->expand();
        $this->nodeValues[] = $node->nodeValue;
    }

    function getNodeValues(): array
    {
        return $this->nodeValues;
    }
}



$valueNodeProcessor = new OpenValueNodeProcessor();
$processor = new XMLProcessor([$valueNodeProcessor]);
$processor->processFile('file.xml');

var_dump($valueNodeProcessor->getNodeValues());

array(3) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
  [2]=>
  string(3) "baz"
}