php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74629 isEmptyElement returns false instead of true
Submitted: 2017-05-22 11:46 UTC Modified: 2017-05-22 14:01 UTC
From: the_djmaze at hotmail dot com Assigned:
Status: Not a bug Package: XML Reader
PHP Version: 7.1.5 OS: GNU/Linux
Private report: No CVE-ID: None
 [2017-05-22 11:46 UTC] the_djmaze at hotmail dot com
Description:
------------
When an empty element has attributes and you loop through them, the isEmptyElement changes from false to true.

Test script:
---------------
<?php
$reader = new XMLReader();
$reader->xml('<?xml version="1.0"?><tr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<td xsi:nil="true"/><td/>
</tr>', null, LIBXML_COMPACT);
while ($reader->read()) {
	switch ($reader->nodeType)
	{
	case XMLReader::ELEMENT:
		echo "{$reader->name}: " . ($reader->isEmptyElement ? 'empty element' : 'has data');
		$attributes = array();
		if ($reader->hasAttributes) {
			while ($reader->moveToNextAttribute()) {
				$attributes[$reader->localName] = $reader->value;
			}
		}
		echo ($reader->isEmptyElement ? ' = empty element' : ' = has data') . "\n";
		break;
	case XMLReader::END_ELEMENT:
		echo "/{$reader->name}\n";
	}
}


Expected result:
----------------
isEmptyElement = true

Actual result:
--------------
isEmptyElement = false

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-22 12:00 UTC] the_djmaze at hotmail dot com
-Status: Open +Status: Closed
 [2017-05-22 12:00 UTC] the_djmaze at hotmail dot com
Never mind, the property name is misleading.
It works when going back using $reader->moveToElement() after reading the attributes
 [2017-05-22 14:01 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Dec 01 06:01:23 2020 UTC