views:

144

answers:

1

Using the XMLReader XML parser in PHP 5.3, I need to get the line number of the current node. A column number or total offset from the beginning of the file would be nice, too.

Hopefully I don't have to use some hack like parsing every raw node string for newlines (with readOuterXML()), but I don't see a getLineNo() property like in the DOM...

A: 

See XMLReader::expand which returns a DOMNode element, which in turn supports getLineNo()

Anshul
This works for some node types (XMLREADER::ELEMENT), but gives incorrect values for others (XMLREADER::END_ELEMENT) and not at all for others (XMLREADER::PI, XMLREADER::DOC_TYPE). I really need something that works for all node types..
scotts