removeNodesMatchingXPath() public method

It does not map to any \SimpleXMLElement function.
public removeNodesMatchingXPath ( string $path ) : void
$path string An XPath path
return void
Example #1
0
 /**
  * Removes nodes that should not be read, like the pronunciation of the Kanji characters.
  * By keeping them, their text content would be added to the read string.
  *
  * @param \Box\Spout\Reader\Wrapper\SimpleXMLElement $parentNode Parent node that may contain nodes to remove
  * @return \Box\Spout\Reader\Wrapper\SimpleXMLElement Cleaned parent node
  */
 protected function removeSuperfluousTextNodes($parentNode)
 {
     $tagsToRemove = ['rPh', 'pPr', 'rPr'];
     foreach ($tagsToRemove as $tagToRemove) {
         $xpath = '//ns:' . $tagToRemove;
         $parentNode->removeNodesMatchingXPath($xpath);
     }
     return $parentNode;
 }
Example #2
0
    /**
     * @return void
     */
    public function testRemoveNodeMatchingXPath()
    {
        $xml = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<worksheet>
    <sheetData>
        <row r="1">
            <c r="A1"><v>0</v></c>
            <c r="A2"><v>1</v></c>
        </row>
    </sheetData>
</worksheet>
XML;
        $element = new SimpleXMLElement($xml);
        $this->assertNotNull($element->getFirstChildByTagName('sheetData'));
        $element->removeNodesMatchingXPath('//sheetData');
        $this->assertNull($element->getFirstChildByTagName('sheetData'));
    }