public getTextValue ( ) : string | ||
Résultat | string |
public function getTextValue() : string
{
if (self::ELEMENT === $this->nodeType && $this->isEmptyElement) {
return '';
}
$depth = 1;
$text = '';
while (0 !== $depth && $this->read()) {
if (isset($this->textTypes[$this->nodeType])) {
$text .= $this->value;
} elseif (self::ELEMENT === $this->nodeType) {
if (!$this->isEmptyElement) {
$depth++;
}
} elseif (self::END_ELEMENT === $this->nodeType) {
$depth--;
}
}
return $text;
}
/** * Tests the getTextValue() method. * * @see \Jyxo\XmlReader::getTextValue() */ public function testGetTextValue() { // In the form: tag (key), expected value (value) $tests = array(); $tests['one'] = 'word'; $tests['second'] = 'two words'; $tests['third'] = 'three simple words'; $tests['forth'] = "\n\t\tfour words on several lines\n\t"; $tests['fifth'] = 'fifth test with tags'; $tests['sixth'] = 'sixth test with tags and inner tags'; $this->reader->open($this->path . '/text.xml'); $this->reader->next('test'); while ($this->reader->read()) { if ($this->reader->nodeType == \XMLReader::ELEMENT) { $this->assertEquals($tests[$this->reader->name], $this->reader->getTextValue()); } } }