Parsing SPML response file in php

1k views Asked by At

I am trying to parse a 4GB+ xml(spml) file formatted as follows. I can parse a test file formatted similarly using SimpleXML [surely with some warnings]; But when I try to parse the same using XMLReader I don get any output. If anybody knows of any solution, please help me

<?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>

However, I get the following Warning messages :

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...
1

There are 1 answers

4
ajreal On

Parsing a 4Gb XML likely will cause a out of memory unless you have sufficient memory,
you can use to PHP Tidy module to repair all the malformed 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