如何使用XMLReader循环遍历多个XML文档声明?

时间:2014-10-31 09:35:59

标签: php xml xmlreader

我有一个XML字符串,它由两个xml文件组成。 (为了便于阅读,我剪切了下面的xml字符串):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" ...

我想循环遍历每个xml文档,并用<a:t>标记替换变量中的文本。下面的代码可以正常工作,但只适用于第一个xml文档。当涉及第二个<?xml version="1.0" encoding="UTF-8" standalone="yes"?> xml声明时,它不会继续。

如何遍历多个xml声明并执行下面的代码?

        $reader = new XMLReader();
        $reader->xml($extract);

        while (@$reader->read()) {
            if (@$reader->nodeType == XMLREADER::ELEMENT && $reader->name === 'a:t'){
                $i++;
                $string = @$reader->readString();
                $extract = str_replace($string, $i, $extract);
            }
        }

0 个答案:

没有答案
相关问题