使用simplexml_load_file()加载XML时出现警告

时间:2016-05-07 02:36:31

标签: php xml

我有一个名为po.xml的XML文件:

0.0
0.0
...

使用以下PHP脚本加载文件时:

<?xml version="1.0" encoding="utf-8"?>
    <DOCUMENT xmlns="po.xsd">
        <PO>
            <HEADER>
                <PO_CODE/>
                <PO_NAME/>
                <REFF_NO/>
            </HEADER>
            <DETAIL>
                <CONT>
                    <NO_CONT/>
                    <UK_CONT/>
                    <NO_SEGEL/>
                    <JNS_CONT/>
                    <ISO_CODE/>
                </CONT>
            <DETAIL>
        </PO>
    </DOCUMENT>

我收到了这些警告:

  

警告:simplexml_load_file():po.xml:2:命名空间警告:xmlns:URI po.xsd&gt;在第3行的C:\ xampp \ htdocs \ inventory \ po.php中不是绝对的

     

警告:simplexml_load_file():在第3行的C:\ xampp \ htdocs \ inventory \ po.php

     

警告:simplexml_load_file():^在C:\ xampp \ htdocs \ inventory \ po.php中行&gt; 3');

我想将po.xml的XML结构作为字符串回显。

2 个答案:

答案 0 :(得分:0)

此示例xml无效。尝试关闭df.m <- structure(list(X1 = c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 1L, 2L, 3L, 4L), X2 = c("b", "b", "b", "b", "e", "e", "e", "e", "t", "t", "t", "t", "w", "w", "w", "w", "e", "e", "e", "e", "e", "e", "e", "e", "n", "n", "n", "n"), value = c(219L, 78L, 250L, 406L, 125L, 78L, 204L, 110L, 125L, 250L, 296L, 172L, 94L, 156L, 829L, 187L, 172L, 172L, 265L, 63L, 109L, 141L, 125L, 156L, 172L, 140L, 203L, 109L)), .Names = c("X1", "X2", "value"), class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28")) df <- structure(c(219L, 78L, 250L, 406L, 125L, 78L, 204L, 110L, 125L, 250L, 296L, 172L, 94L, 156L, 829L, 187L, 172L, 172L, 265L, 63L, 109L, 141L, 125L, 156L, 172L, 140L, 203L, 109L), .Dim = c(4L, 7L), .Dimnames = list(NULL, c("b", "e", "t", "w", "e", "e", "n"))) 代码。

答案 1 :(得分:0)

xml中有两个错误

首先,xmlns="po.xsd"应使用绝对路径。

来自libxml网页http://www.xmlsoft.org/namespaces.html

  

名称空间值必须是绝对URL,但URL不必指向Web上的任何现有资源。

此问题已在此处讨论过:Error loading xml in php (not absolute)

如果您使用xmlns="http://www.example.com/po.xsd"之类的内容删除或修复此部分,则应该有效。

正如Jeff Pucket所说,您的代码<DETAIL>应该已关闭

<DETAIL>
   <CONT>
   <NO_CONT/>
   ....
   </CONT>
</DETAIL>