Home  >  Article  >  Backend Development  >  读取XML获取不了节点值?

读取XML获取不了节点值?

WBOY
WBOYOriginal
2016-06-06 20:35:351157browse

<code><?php $reader = new XMLReader();
$reader->open("1.xml");                                                     
while($reader->read()){
if($reader->nodeType==XMLREADER::ELEMENT) {
             if ($reader->localName == "humans") {
                 //已经能进if语句,但是获取不了value
                 echo $reader->value;
             }
    }
}
?>
</code>

XML文件1.xml:

<code><?xml version="1.0"?>

  <humans>
  hello
  </humans>
</code>

$reader->value无效,什么原因?请教!

回复内容:

<code><?php $reader = new XMLReader();
$reader->open("1.xml");                                                     
while($reader->read()){
if($reader->nodeType==XMLREADER::ELEMENT) {
             if ($reader->localName == "humans") {
                 //已经能进if语句,但是获取不了value
                 echo $reader->value;
             }
    }
}
?>
</code>

XML文件1.xml:

<code><?xml version="1.0"?>

  <humans>
  hello
  </humans>
</code>

$reader->value无效,什么原因?请教!

if语句少了$reader->read();

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn