1

我正在尝试解析格式如下的 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>

但是,我收到以下警告消息:

Warning: XMLReader::read() [xmlreader.read]: file:///C:/wamp/www/xml_reader/xml_file.xml:3: namespace error : xmlns:spml: 'urn:siemens:names:prov:gw:SP ML:2:0' is not a valid URI in...
4

1 回答 1

0

除非您有足够的内存,否则解析 4Gb XML 可能会导致内存不足,
您可以使用PHP Tidy 模块来修复所有格式错误的 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
于 2011-11-29T15:08:25.867 回答