You are here:  » Empty lines when parsing file


Empty lines when parsing file

Submitted by pflikweert on Thu, 2005-12-08 09:17 in

Hi, I try to parse one xml file, but i get empty lines in the repeating stuff in the xml, only the last element is show.
Example output:

 [SERVICEPART/EVENTS] =>
    [SERVICEPART/EVENTS/EVENT] =>
    [SERVICEPART/EVENTS/EVENT/TIMESINCESTART] => 43.172
    [SERVICEPART/EVENTS/EVENT/EVENTNAME] => tDisconnect
    [SERVICEPART/EVENTS/EVENT/LEG] => b

There are more repeating blocks in the xml file.

Can someone help me?

Used the code for php4:

<?php
  set_time_limit
(0);
  require_once(
"MagicParser.o");
  function 
myRecordHandler($record)
  {
   
print_r($record);
  }
  
//MagicParser_getFormat("sdr.xml");
  
MagicParser_parse("sdr.xml","myRecordHandler""XML|WEBTEL/SDRS/SDR/");
?>

The xml file

<?xml version="1.0"?>
<WebTel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./sdr.xsd">
<sdrs>
<sdr serviceReference="2e45a5c:1057b4934ec:2b5a" version="2.0">
<serviceName>pinout</serviceName>
<serviceProvider>SampleServiceProvider</serviceProvider>
<subscriptionID>20f567:102bef4fcc3:-7ac4</subscriptionID>
<endUser>yourid</endUser>
<creationTime>2005-08-11T07:27:20+01:00</creationTime>
<nrOfServiceParts>1</nrOfServiceParts>
<servicePart sequenceNr="1" type="call">
<number type="firstCalledPartyNumber">
<screened>+31502100000</screened>
</number>
<number type="secondCalledPartyNumber">
<screened>+31502100098</screened>
</number>
<progress>900</progress>
<status>completed</status>
<startTime>2005-08-11T07:27:20+01:00</startTime>
<modificationTime>2005-08-11T07:28:54+01:00</modificationTime>
<connectTimeA>2005-08-11T07:27:26+01:00</connectTimeA>
<disconnectTimeA>2005-08-11T07:28:54+01:00</disconnectTimeA>
<connectTimeB nil="true"></connectTimeB>
<disconnectTimeB nil="true"></disconnectTimeB>
<durationA>88</durationA>
<durationB nil="true"></durationB>
<serviceLevel>
<serviceRequest>0</serviceRequest>
</serviceLevel>
<premiumTariff nil="true"></premiumTariff>
<serviceOptions>PNR=0;PSR=redirect;</serviceOptions>
<events>
<event>
<timeSinceStart>0.016</timeSinceStart>
<eventName>webtelInitCall</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>2.485</timeSinceStart>
<eventName>callAccepted</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>6.469</timeSinceStart>
<eventName>tAnswer</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>29.454</timeSinceStart>
<eventName>webtelDTMF</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>29.719</timeSinceStart>
<eventName>webtelRedirReceived</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>34.079</timeSinceStart>
<eventName>webtelAnnouncementComplete</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>35.313</timeSinceStart>
<eventName>callAccepted</eventName>
<leg>b</leg>
</event>
<event>
<timeSinceStart>35.344</timeSinceStart>
<eventName>tcapEnd</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>94.625</timeSinceStart>
<eventName>oDisconnect</eventName>
<leg>b</leg>
</event>
<event>
<timeSinceStart>94.625</timeSinceStart>
<eventName>tcapEnd</eventName>
<leg>b</leg>
</event>
</events>
</servicePart>
</sdr>
<sdr serviceReference="2e45a5c:1057b4934ec:1f3d" version="2.0">
<serviceName>connectab</serviceName>
<serviceProvider>SampleServiceProvider</serviceProvider>
<subscriptionID>29fe451:fefab23097:-7fce</subscriptionID>
<endUser>yourid</endUser>
<creationTime>2005-08-10T13:49:04+01:00</creationTime>
<nrOfServiceParts>1</nrOfServiceParts>
<servicePart sequenceNr="1" type="call">
<number type="firstCalledPartyNumber">
<screened>+31502100575</screened>
</number>
<number type="secondCalledPartyNumber">
<screened>+31502100348</screened>
</number>
<progress>900</progress>
<status>completed</status>
<startTime>2005-08-11T07:37:24+01:00</startTime>
<modificationTime>2005-08-11T07:38:07+01:00</modificationTime>
<connectTimeA>2005-08-11T07:37:29+01:00</connectTimeA>
<disconnectTimeA>2005-08-11T07:38:07+01:00</disconnectTimeA>
<connectTimeB>2005-08-11T07:37:37+01:00</connectTimeB>
<disconnectTimeB>2005-08-11T07:38:07+01:00</disconnectTimeB>
<durationA>38</durationA>
<durationB>30</durationB>
<serviceLevel>
<serviceRequest>0</serviceRequest>
</serviceLevel>
<premiumTariff nil="true"></premiumTariff>
<serviceOptions nil="true"></serviceOptions>
<events>
<event>
<timeSinceStart>0.0</timeSinceStart>
<eventName>webtelInitCall</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>1.625</timeSinceStart>
<eventName>callAccepted</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>5.391</timeSinceStart>
<eventName>tAnswer</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>6.532</timeSinceStart>
<eventName>callAccepted</eventName>
<leg>b</leg>
</event>
<event>
<timeSinceStart>6.563</timeSinceStart>
<eventName>tcapEnd</eventName>
<leg>a</leg>
</event>
<event>
<timeSinceStart>13.547</timeSinceStart>
<eventName>tAnswer</eventName>
<leg>b</leg>
</event>
<event>
<timeSinceStart>43.157</timeSinceStart>
<eventName>tcapEnd</eventName>
<leg>b</leg>
</event>
<event>
<timeSinceStart>43.172</timeSinceStart>
<eventName>tDisconnect</eventName>
<leg>b</leg>
</event>
</events>
</servicePart>
</sdr>
</sdrs>
</WebTel>

Submitted by support on Thu, 2005-12-08 09:43

Hi there,

This is a known limitation with the way Magic Parser works with XML, and something i'm going to get documented so that it can be more easily understood.

What you have in your XML is a second level of repeating element (SERVICEPART/EVENTS) within the top level WEBTEL/SDRS/SDR/ that you are interested in. The empty lines are the higher level container sections that contain no data - just child elements; but Magic Parser has to return these empty values as it is not possible to tell from the markup whether or not the empty space is relavent - consider the XHTML scenario where you may have text between one element and the next child element.

In this exact scenario with the example XML posted; you would be able to extract all SERVICEPART/EVENT information by using a 2 stage process; parsing once to extract all the top level information within WEBTEL/SDRS/SDR; and then again using WEBTEL/SDRS/SDR/SERVICEPART/EVENT as the repeating element value. Your code would look something like this:

<?php
  
require("MagicParser.php");
  function 
mySDRHandler($record)
  {
    
print_r($record);
  }
  function 
myEVENTHandler($record)
  {
    
print_r($record);
  }
  
// parse once to extract SDR level values
  
MagicParser_parse("sdr.xml","mySDRHandler""XML|WEBTEL/SDRS/SDR/");
  
// parse again to extract EVENT level values
  
MagicParser_parse("sdr.xml","myEVENTHandler""XML|WEBTEL/SDRS/SDR/SERVICEPART/EVENT/");
?>

Hope this helps!