将XML文件转换为Json失败

时间:2017-06-19 11:46:13

标签: php json xml

我不明白这段代码在读取XML文件版本1.0并转换为json

时出了什么问题
$xml = simplexml_load_file('/Volumes/ABKDatos/warehouse/tmp/1.xml');

libxml_use_internal_errors(true);

if ($xml === false)
{
   echo "Error cargando XML".PHP_EOL;
   foreach(libxml_get_errors() as $error) {
   echo "\t", $error->message;
   }
}

var_dump($xml->count());

$json = json_encode($xml);
$array = json_decode($json,TRUE);
var_dump($array)

展示

int(0)
array(0) {
}      

XML File

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/3.2/style/exchange.xsl"?>
<ops:world-patent-data xmlns="http://www.epo.org/exchange" xmlns:ops="http://ops.epo.org" xmlns:xlink="http://www.w3.org/1999/xlink">
    <ops:biblio-search total-result-count="185">
        <ops:query syntax="CQL">ti all "organic plastic" AND pd within "20070101,20170610"</ops:query>
        <ops:range begin="1" end="100"/>
        <ops:search-result>
            <ops:publication-reference system="ops.epo.org" family-id="58738760">
                <document-id document-id-type="docdb">
                    <country>US</country>
                    <doc-number>9665818</doc-number>
                    <kind>B1</kind>
                </document-id>
            </ops:publication-reference>
            <ops:publication-reference system="ops.epo.org" family-id="53524784">
                <document-id document-id-type="docdb">
                    <country>US</country>
                    <doc-number>2017121644</doc-number>
                    <kind>A1</kind>
                </document-id>
            </ops:publication-reference>
   ...
       </ops:search-result>
    </ops:biblio-search>
</ops:world-patent-data>

0 个答案:

没有答案