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
用php解析SPML响应文件_Php_Xml_Parsing_Large Files_Spml - Fatal编程技术网

用php解析SPML响应文件

用php解析SPML响应文件,php,xml,parsing,large-files,spml,Php,Xml,Parsing,Large Files,Spml,我试图解析一个4GB+xml(spml)文件,格式如下。我可以使用SimpleXML解析格式类似的测试文件[当然有一些警告];但是当我尝试使用XMLReader解析相同的内容时,我没有得到任何输出。如果有人知道任何解决办法,请帮助我 <?xml version="1.0" encoding="UTF-8"?> <spml:searchResponse executionTime="6821151" language="en_us" requestID="caac94d2-a5d

我试图解析一个4GB+xml(spml)文件,格式如下。我可以使用SimpleXML解析格式类似的测试文件[当然有一些警告];但是当我尝试使用XMLReader解析相同的内容时,我没有得到任何输出。如果有人知道任何解决办法,请帮助我

<?xml version="1.0" encoding="UTF-8"?>
<spml:searchResponse executionTime="6821151" language="en_us" requestID="caac94d2-a5df-4bc0-bc75-8ab71ed02b37" result="success" xmlns:spml="urn:siemens:names:prov:gw:SPML:2:0">
<version xmlns:subscriber="urn:siemens:names:prov:gw:HLR_SUBSCRIBER:4:5">HLR_SUBSCRIBER_v45</version>
<objects xmlns:ns2="urn:siemens:names:prov:gw:HLR_SUBSCRIBER:4:5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="2:Subscriber">
    <identifier>412012000356395</identifier>
    <auc>
        <imsi>123123123423423</imsi>
        <encKey>1A07CD1EEA637E810AA4850668F290AD</encKey>
        <algoId>0</algoId>
        <kdbId>1</kdbId>
        <acsub>1</acsub>
    </auc>
    <hlr>
        <ntype>single</ntype>
        <mobileSubscriberType>genericSubscriber</mobileSubscriberType>
        <wllSubscriber>false</wllSubscriber>
        <mscat>10</mscat>
        <odboc>0</odboc>
        <odbic>0</odbic>
        <odbr>0</odbr>
        <odboprc>0</odboprc>
        <odbssm>0</odbssm>
        <clip>true</clip>
        <clipOverride>false</clipOverride>
        <colpOverride>false</colpOverride>
        <hold>true</hold>
        <mpty>true</mpty>
        <nwa>1</nwa>
        <sr>2</sr>
        <odbsci>0</odbsci>
        <ts11>
            <msisdn>123456</msisdn>
        </ts11>
        <ts21>
            <msisdn>123456</msisdn>
        </ts21>
        <ts22>
            <msisdn>123456</msisdn>
        </ts22>
        <caw>
            <basicServiceGroup>abcd-telephony</basicServiceGroup>
            <status>5</status>
        </caw>
        <isActiveIMSI>false</isActiveIMSI>
        <actIMSIGprs>false</actIMSIGprs>
        <obGprs>0</obGprs>
        <optimalRouting>true</optimalRouting>
        <ndcLac>70</ndcLac>
        <smscsi>
            <operatorServiceName>IN2PPSSMS</operatorServiceName>
            <csiState>1</csiState>
            <csiNotify>2</csiNotify>
        </smscsi>
        <ocsi>
            <operatorServiceName>IN2MOC</operatorServiceName>
            <csiState>1</csiState>
            <csiNotify>2</csiNotify>
        </ocsi>
        <tcsi>
            <operatorServiceName>IN2MTC-T</operatorServiceName>
            <csiState>1</csiState>
            <csiNotify>2</csiNotify>
        </tcsi>
        <ucsiserv>IN2USSD</ucsiserv>
        <vlrMobData>
            <vlrIdValid>false</vlrIdValid>
            <mobileTerminatingCallPossible>true</mobileTerminatingCallPossible>
            <plmnAllowed>true</plmnAllowed>
            <roamingAreaAllowed>true</roamingAreaAllowed>
            <mscAreaRestrictedReceived>false</mscAreaRestrictedReceived>
            <msPurged>false</msPurged>
            <supportedCAMELPhaseByVLR>1</supportedCAMELPhaseByVLR>
            <supportedMAPVersionForLUP>3</supportedMAPVersionForLUP>
            <featuresNotSupportedByVLR>extCamel</featuresNotSupportedByVLR>
            <featuresNotSupportedByVLR>oICK</featuresNotSupportedByVLR>
            <prohFtnoUpdInVlrFail>false</prohFtnoUpdInVlrFail>
            <ts10BarrByCb>0</ts10BarrByCb>
            <ts20BarrByCb>0</ts20BarrByCb>
            <ts60BarrByCb>0</ts60BarrByCb>
            <bs20BarrByCb>0</bs20BarrByCb>
            <bs30BarrByCb>0</bs30BarrByCb>
            <bs40BarrByCb>0</bs40BarrByCb>
            <vlrSupportsLongFtno>false</vlrSupportsLongFtno>
        </vlrMobData>
        <sgsnMobData>
            <sgsnIdValid>false</sgsnIdValid>
            <plmnAllowed>true</plmnAllowed>
            <roamingAreaAllowed>true</roamingAreaAllowed>
            <gprsAllowed>true</gprsAllowed>
            <supportedCAMELPhaseBySGSN>1</supportedCAMELPhaseBySGSN>
            <supportedMAPVersionForLUP>3</supportedMAPVersionForLUP>
            <featuresNotSupportedBySGSN>extCamel</featuresNotSupportedBySGSN>
            <sgsnCamelNot>false</sgsnCamelNot>
            <sgsnExtQos>false</sgsnExtQos>
        </sgsnMobData>
    </hlr>
</objects></spml:searchResponse>

解析4Gb XML可能会导致内存不足,除非您有足够的内存,
您可以使用修复所有格式错误的XML

$ops = array();
$ops['input-xml']  =
$ops['output-xml'] = TRUE;

$tidy = new Tidy($source_file, $ops);
$tidy->isXML();
$tidy->cleanRepair();

// output the fixed xml
ob_start();
echo $tidy;
$buf = ob_get_clean();
file_put_contents($target_file, $buf);

// if you can run from console
// then you can skip the above
// php -q parse.php > new.xml

请在调用XMLReader时添加代码,并说明如何获取输出。否则就很难说了。请重新粘贴您的XML示例,因为没有任何标记是visisble$reader=new XMLReader();如果(!$reader->open(“xml_file.xml”){die(“无法打开文件”);}如果(!$reader->read())die(“无法准备”);虽然($reader->read(){die(“sdfsdf”);}嗯,我在10GB刀片上运行它:),但问题是我想让它更有效率。你能建议最好的方法吗?我已经检查过了,几乎每个人都建议XMLReader用于大文件,尽管它很难处理——我指的是它的代码。不管怎样,我正在尝试你的建议,非常感谢你的回答。嗨,ajreal,我尝试了你整理xml然后阅读的方法。还没有运气。知道吗?哪一部分不走运?新修复的XML是否仍然出现解析错误?确切地说,我仍然收到相同的警告:S
$ops = array();
$ops['input-xml']  =
$ops['output-xml'] = TRUE;

$tidy = new Tidy($source_file, $ops);
$tidy->isXML();
$tidy->cleanRepair();

// output the fixed xml
ob_start();
echo $tidy;
$buf = ob_get_clean();
file_put_contents($target_file, $buf);

// if you can run from console
// then you can skip the above
// php -q parse.php > new.xml