使用PHP的XMLReader,如何获取当前节点的行号? [英] Using PHP's XMLReader, how do I get the line number of the current node?

查看:152
本文介绍了使用PHP的XMLReader,如何获取当前节点的行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在PHP 5.3中使用XMLReader XML解析器,我需要获取当前节点的行号.从文件开头开始的列号或总偏移量也很好.

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.

希望我不必使用一些技巧,例如解析每个原始节点字符串以换行符(使用readOuterXML()),但是我却没有像DOM中那样看到getLineNo()属性...

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...

推荐答案

请参见XMLReader::expand,它返回DOMNode元素,而该元素又支持getLineNo()

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

这篇关于使用PHP的XMLReader,如何获取当前节点的行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆