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

读取XML获取不了节点值?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:35:35
Original
1193 people have browsed it

<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>
Copy after login
Copy after login

XML文件1.xml:

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

  <humans>
  hello
  </humans>
</code>
Copy after login
Copy after login

$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>
Copy after login
Copy after login

XML文件1.xml:

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

  <humans>
  hello
  </humans>
</code>
Copy after login
Copy after login

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

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

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template