Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP7.x simpleXML上迁移后,给出;“节点不再存在”;_Php_Xml_Parsing_Php 7 - Fatal编程技术网

在PHP7.x simpleXML上迁移后,给出;“节点不再存在”;

在PHP7.x simpleXML上迁移后,给出;“节点不再存在”;,php,xml,parsing,php-7,Php,Xml,Parsing,Php 7,我尝试从php5.6迁移到php7.x,但在读取xml时遇到问题 如果我在php5.6上运行这段代码,那么在php7.x上会出现一些奇怪的错误 echo 'LIBXML_VERSION ' . LIBXML_VERSION . "\n"; echo 'LIBXML_DOTTED_VERSION ' . LIBXML_DOTTED_VERSION . "\n"; libxml_use_internal_errors(true); $entryC

我尝试从php5.6迁移到php7.x,但在读取xml时遇到问题

如果我在php5.6上运行这段代码,那么在php7.x上会出现一些奇怪的错误

    echo 'LIBXML_VERSION ' . LIBXML_VERSION . "\n";
echo 'LIBXML_DOTTED_VERSION ' . LIBXML_DOTTED_VERSION . "\n";
libxml_use_internal_errors(true);


 $entryContent ='<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
                         xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
                         xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
                         xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
                         xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
                         xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
                         xmlns:xlink="http://www.w3.org/1999/xlink"
                         xmlns:dc="http://purl.org/dc/elements/1.1/"
                         xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
                         xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
                         xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
                         xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
                         xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
                         xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
                         xmlns:math="http://www.w3.org/1998/Math/MathML"
                         xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
                         xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
                         xmlns:ooo="http://openoffice.org/2004/office"
                         xmlns:ooow="http://openoffice.org/2004/writer"
                         xmlns:oooc="http://openoffice.org/2004/calc"
                         xmlns:dom="http://www.w3.org/2001/xml-events"
                         xmlns:xforms="http://www.w3.org/2002/xforms"
                         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xmlns:field="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:field:1.0"
                         office:version="1.1">
    <office:scripts/>
    <office:body>
        <office:spreadsheet>
            <table:table table:name="Data">
            <table:table-column table:style-name="co0"/>
            <table:table-column table:style-name="co0"/>
            <table:table-column table:style-name="co0"/>

            <table:table-row>
                <table:table-cell office:value-type="string"
                    office:value="Mar 16, 2017">
                <text:p>Mar 16, 2017</text:p>
                </table:table-cell>
                <table:table-cell office:value-type="string"
                    office:value="2.0E">
                <text:p>2.0E</text:p>
                </table:table-cell>
            </table:table-row>

            <table:table-row>
                <table:table-cell office:value-type="string"
                    office:value="id"
                    table:style-name="ceHeader">
                <text:p>id</text:p>
                </table:table-cell>

                <table:table-cell office:value-type="string"
                    office:value="tag1"
                    table:style-name="ceHeader">
                <text:p>tag1</text:p>
                </table:table-cell>

                <table:table-cell office:value-type="string"
                    office:value="tag2"
                    table:style-name="ceHeader">
                <text:p>tag2</text:p>
                </table:table-cell>
            </table:table-row>

            <table:table-row>
                <table:table-cell office:value-type="string"
                    office:value="8d427c81bae5a27d07fa2d68eb348fbdd8e83571">
                <text:p>8d427c81bae5a27d07fa2d68eb348fbdd8e83571</text:p>
                </table:table-cell>
                <table:table-cell office:value-type="string"
                    office:value="1">
                <text:p>1</text:p>
                </table:table-cell>
                <table:table-cell office:value-type="string"
                    office:value="0">
                <text:p>0</text:p>
                </table:table-cell>
            </table:table-row>

            <table:table-row>
                <table:table-cell office:value-type="string"
                    office:value="e04913657b418d19838b920bc379fea9c4b7c76a">
                <text:p>e04913657b418d19838b920bc379fea9c4b7c76a</text:p>
                </table:table-cell>
                <table:table-cell office:value-type="string"
                    office:value="0">
                <text:p>0</text:p>
                </table:table-cell>
                <table:table-cell office:value-type="string"
                    office:value="1">
                <text:p>1</text:p>
                </table:table-cell>
            </table:table-row>

            </table:table>
        </office:spreadsheet>
    </office:body>
</office:document-content>
 ';
 
$xml = simplexml_load_string($entryContent, 'SimpleXMLElement');
if ($xml === false) {
    echo "Failed loading XML\n";
    foreach(libxml_get_errors() as $error) {
        echo "\t", $error->message;
    }
}

$ns = $xml->getNamespaces(true);
$spreadsheetXml = $xml->children($ns['office'])->{'body'}->{'spreadsheet'};

$headerRowXml = $spreadsheetXml->children($ns['table'])->{'table'}->{'table-row'}->{1};
print_r($headerRowXml);
print_r($headerRowXml->children($ns['table'])->{'table-cell'}->{1}->children($ns['text'])->{0});
print_r(libxml_get_errors());

此修复程序在php7.x中如何工作?

安装
php7.0-xml
软件包并重新启动您的服务器软件包php71w-xml-7.1.2-1.w6.x86_64已安装,最新版本Nothing to doI查找解决方案将{table-row'}->{1}替换为{table-row'}[1]使用php7和php5.6安装
php7.0-xml
package并重新启动您的服务器包php71w-xml-7.1.2-1.w6.x86_64已安装,最新版本Nothing to doI查找解决方案将{table-row'}->{1}替换为{table-row'}[1]使用php7和php5.6
    LIBXML_VERSION 20902
LIBXML_DOTTED_VERSION 2.9.2
SimpleXMLElement Object
(
    [table-cell] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [style-name] => ceHeader
                        )

                )

            [1] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [style-name] => ceHeader
                        )

                )

            [2] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [style-name] => ceHeader
                        )

                )

        )

)
SimpleXMLElement Object
(
    [0] => tag1
)
Array
(
)