Element atrributes in case statement - php to xml

Alles, was PHP betrifft, kann hier besprochen werden.

Element atrributes in case statement - php to xml

Postby sanei05 » 08. December 2013 14:13

Hi,

I got a xml file. I need to write a php script to parse it and display in a webpage. I wrote a below code for the xml (below). I able to get the output as mentioned. but the element attribute under maesinfo, granperiod is not getting displayed. Can you please help me. .I am in learning phase of php and trying to do my best to have a php script for users.

Code: Select all
<?php
//Initialize the XML parser
$parser=xml_parser_create();

//Function to use at the end of an element

//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
  {
  switch($element_name)
    {
    case "MEASINFO":
    echo "MEASINFO <br>";
    break;
    case "GRANPERIOD":
    echo "GRANPERIOD:<br>";
    break;
    case "GRANPERIOD":
    echo "GRANPERIOD: <br>";
    break;
    case "GRANPERIOD-DURATION":
    echo "GRANPERIOD-DURATION: <br>";
    break;
    case "GRANPERIOD-ENDTIME":
    echo "GRANPERIOD-ENDTIME: <br> ";
   break;
   case "REPPERIOD":
   echo "REPPERIOD <br>";
   break;
   case "MEASTYPES":
   echo "MEASTYPES <br>";
   break;
   case "MEASVALUE":
   echo "MEASVALUE ";
   break;
   case "MEASVALUE-MEASOBJLDN":
   echo "MEASVALUE-MEASOBJLDN: <br>";
   
   break;
   case "MEASVALUE/MEASRESULTS":
   echo "MEASVALUE/MEASRESULTS <br>";
    }
  }


function stop($parser,$element_name)
  {
  echo "<br>";
  }

//Function to use when finding character data
function char($parser,$data)
  {
  echo $data;
  }

//Specify element handler
xml_set_element_handler($parser,"start","stop");

//Specify data handler
xml_set_character_data_handler($parser,"char");

//Open XML file
$fp=fopen("record1.xml","r");

//Read data
while ($data=fread($fp,4096))
  {
  xml_parse($parser,$data,feof($fp)) or
  die (sprintf("XML Error: %s at line %d",
  xml_error_string(xml_get_error_code($parser)),
  xml_get_current_line_number($parser)));
  }

//Free the XML parser
xml_parser_free($parser);
?>



XML file
=========

<?xml version="1.0" encoding="UTF-8"?>
<measCollecFile xmlns="http://latest/nmc-omc/cmNrm.doc#measCollec" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://latest/nmc-omc/cmNrm.doc#measCollec schema\pmResultSchedule.xsd">
<fileHeader fileFormatVersion="32.435 V7.2" vendorName="Huawei">
<fileSender elementType="USN"/>
<measCollec beginTime="2013-12-01T00:00:00+04:00"/>
</fileHeader>
<measData>
<managedElement userLabel="USN_AR"/>
<measInfo measInfoId="11854767">
<granPeriod duration="PT3600S" endTime="2013-12-01T01:00:00+04:00"/>
<repPeriod duration="PT3600S"/>
<measTypes>MME-init PDN disconnection request Times;MME-init PDN disconnection success Times;PDN disconnect fail Times(#35 PTI already in use);PDN disconnect fail Times(#43 Unknown EPS bearer ctx);PDN disconnect fail Times(#49 Last PDN disconn not allowed);PDN disconnect fail Times(#95-111 Protocol err, unspec);PDN disconnect fail Times(#96 Invalid mandatory information);PDN disconnect request Times;PDN disconnect success Times;</measTypes>
<measValue measObjLdn="USN_AR/Whole System:USN_AR">
<measResults>0 0 0 0 0 0 0 0 0 </measResults>
</measValue>
</measInfo>
<measInfo measInfoId="117440618">
<granPeriod duration="PT3600S" endTime="2013-12-01T01:00:00+04:00"/>
<repPeriod duration="PT3600S"/>
<measTypes>Components sent by the node;Componets received by the node;Reject component received by the node;Reject component sent by the node;Return error component received by the node;Return error component sent by the node;Return result received ultilizations(not last);Return result ultilizations received by the node;Return result ultilizations sent by the node;Return result ultilizations sent(not last);</measTypes>
<measValue measObjLdn="USN_AR/Whole System:USN_AR">
<measResults>23839 2067 0 0 3235 1 0 19163 2065 0 </measResults>
</measValue>
</measInfo>
<measInfo measInfoId="117440600">
<granPeriod duration="PT3600S" endTime="2013-12-01T01:00:00+04:00"/>
<repPeriod duration="PT3600S"/>
<measTypes>Iu mode Foreign subscribers act PDP context accept;Iu mode Foreign subscribers act PDP context reject;Iu mode Foreign subscribers init PDP context act;Iu mode MS init IPv4 PDP ctx act;Iu mode MS init IPv4 PDP ctx act reject;Iu mode MS init IPv4 PDP ctx act success;Iu mode MS init IPv6 PDP ctx act;Iu mode MS init IPv6 PDP ctx act reject;Iu mode MS init IPv6 PDP ctx act success;Iu mode MS init PDP context Max act time delay;Iu mode MS init PDP context Mean act time delay;Iu mode MS init PDP context act;Iu mode MS init PDP context act reject;Iu mode MS init PDP context act reject with dynamic addr;Iu mode MS init PDP context act success;Iu mode MS init PDP context act success rate;Iu mode MS init PDP context act success with dynamic addr;Iu mode MS init PDP context act with dynamic addr;Iu mode MS init PDP context sec act success;Iu mode Ms PDP Context Total act time delay;Iu mode Ms PDP Context act complete Total times;Iu mode NET PDP context act fail;Iu mode NET PDP context act fail ((insufficient net resources));Iu mode NET PDP context act fail (DNS resolution fail);Iu mode NET PDP context act fail (Operator Determined Barring);Iu mode NET PDP context act fail (QoS negotiation fail);Iu mode NET PDP context act fail (missing or unknown APN);Iu mode NET PDP context act fail (rejected by GGSN);Iu mode NET PDP context act fail (service not supported);Iu mode NET PDP context act fail (service unsubscribed);Iu mode NET PDP context act fail (unknown PDP addr or type);Iu mode NET PDP context act fail (user authentication fail);Iu mode NET PDP context act fail(APN Restriction);Iu mode NET PDP context act fail(Ge fail);Iu mode NET PDP context act fail(RAB assignment fail);Iu mode NET PDP context act fail(Unspecified Reason);Iu mode Network init IPv4 PDP ctx act;Iu mode Network init IPv4 PDP ctx act success;Iu mode Network init IPv6 PDP ctx act;Iu mode Network init IPv6 PDP ctx act success;Iu mode Network init PDP context act;Iu mode Network init PDP context act success;Iu mode Network init sec PDP context act;Iu mode Network init sec PDP context act success;Iu mode PDP context act fail (DNS resolution fail);Iu mode PDP context act fail (QoS negotiation fail);Iu mode PDP context act fail (RAB assignment fail);Iu mode PDP context act fail (rejected by GGSN);Iu mode PDP context act fail(APN Restriction);Iu mode PDP context act fail(Ge fail);Iu mode PDP context act fail(insufficient net resources);Iu mode PDP context act fail(missing or unknown APN);Iu mode PDP context act fail(service not supported);Iu mode PDP context act fail(service unsubscribed);Iu mode PDP context act fail(unknown PDP addr or type);Iu mode PDP context act fail(unspecific reason);Iu mode PDP context act fail(user authentication fail);Iu mode PDP context act request times per subscriber @BH;Iu mode PDP context sec act;Iu mode PDP context sec act fail(Ge fail);Iu mode PDP context sec act fail(Unspecified Reason);Iu mode PDP context sec act fail(net resource insufficient);Iu mode PDP context sec act fail(rejected by GGSN);Iu mode PDP context sec act fail(unknown PDP context);Iu mode PDP context sec act reject;Iu mode PDP ctx act fail (Operator Determined Barring);Iu mode PDP ctx sec act fail (Operator Determined Barring);Iu mode active One Tunnel PDP Success;Iu mode active One Tunnel PDP fail;Iu mode active One Tunnel PDP reject(CAMEL);Iu mode active One Tunnel PDP reject(GTP Versions);Iu mode active Two Tunnel PDP Success;Iu mode active Two Tunnel PDP fail;Iu mode maximum MS init PDP context act;Iu mode secondary IPv4 PDP ctx act;Iu mode secondary IPv4 PDP ctx act success;Iu mode secondary IPv6 PDP ctx act;Iu mode secondary IPv6 PDP ctx act success;</measTypes>
<measValue measObjLdn="USN_AR/Whole System:USN_AR">
<measResults>21 72 93 13476 5492 7984 5 0 5 9540 783 13596 5568 5567 8028 59.047 8027 13594 0 6288830 8028 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 3 0 3427 41 0 0 162 0 0 452 0 1 1482 0.472 0 0 0 0 0 0 0 0 0 0 0 0 0 8028 4935 59 0 0 0 0 </measResults>
</measValue>
</measInfo>
</measData>
<fileFooter>
<measCollec endTime="2013-12-01T01:00:00+04:00"/>
</fileFooter>
</measCollecFile>



Output in webpage





MEASINFO
GRANPERIOD:

REPPERIOD

MEASTYPES
MME-init PDN disconnection request Times;MME-init PDN disconnection success Times;PDN disconnect fail Times(#35 PTI already in use);PDN disconnect fail Times(#43 Unknown EPS bearer ctx);PDN disconnect fail Times(#49 Last PDN disconn not allowed);PDN disconnect fail Times(#95-111 Protocol err, unspec);PDN disconnect fail Times(#96 Invalid mandatory information);PDN disconnect request Times;PDN disconnect success Times;
MEASVALUE 0 0 0 0 0 0 0 0 0


MEASINFO
GRANPERIOD:

REPPERIOD

MEASTYPES
Components sent by the node;Componets received by the node;Reject component received by the node;Reject component sent by the node;Return error component received by the node;Return error component sent by the node;Return result received ultilizations(not last);Return result ultilizations received by the node;Return result ultilizations sent by the node;Return result ultilizations sent(not last);
MEASVALUE 23839 2067 0 0 3235 1 0 19163 2065 0


MEASINFO
GRANPERIOD:

REPPERIOD

MEASTYPES
Iu mode Foreign subscribers act PDP context accept;Iu mode Foreign subscribers act PDP context reject;Iu mode Foreign subscribers init PDP context act;Iu mode MS init IPv4 PDP ctx act;Iu mode MS init IPv4 PDP ctx act reject;Iu mode MS init IPv4 PDP ctx act success;Iu mode MS init IPv6 PDP ctx act;Iu mode MS init IPv6 PDP ctx act reject;Iu mode MS init IPv6 PDP ctx act success;Iu mode MS init PDP context Max act time delay;Iu mode MS init PDP context Mean act time delay;Iu mode MS init PDP context act;Iu mode MS init PDP context act reject;Iu mode MS init PDP context act reject with dynamic addr;Iu mode MS init PDP context act success;Iu mode MS init PDP context act success rate;Iu mode MS init PDP context act success with dynamic addr;Iu mode MS init PDP context act with dynamic addr;Iu mode MS init PDP context sec act success;Iu mode Ms PDP Context Total act time delay;Iu mode Ms PDP Context act complete Total times;Iu mode NET PDP context act fail;Iu mode NET PDP context act fail ((insufficient net resources));Iu mode NET PDP context act fail (DNS resolution fail);Iu mode NET PDP context act fail (Operator Determined Barring);Iu mode NET PDP context act fail (QoS negotiation fail);Iu mode NET PDP context act fail (missing or unknown APN);Iu mode NET PDP context act fail (rejected by GGSN);Iu mode NET PDP context act fail (service not supported);Iu mode NET PDP context act fail (service unsubscribed);Iu mode NET PDP context act fail (unknown PDP addr or type);Iu mode NET PDP context act fail (user authentication fail);Iu mode NET PDP context act fail(APN Restriction);Iu mode NET PDP context act fail(Ge fail);Iu mode NET PDP context act fail(RAB assignment fail);Iu mode NET PDP context act fail(Unspecified Reason);Iu mode Network init IPv4 PDP ctx act;Iu mode Network init IPv4 PDP ctx act success;Iu mode Network init IPv6 PDP ctx act;Iu mode Network init IPv6 PDP ctx act success;Iu mode Network init PDP context act;Iu mode Network init PDP context act success;Iu mode Network init sec PDP context act;Iu mode Network init sec PDP context act success;Iu mode PDP context act fail (DNS resolution fail);Iu mode PDP context act fail (QoS negotiation fail);Iu mode PDP context act fail (RAB assignment fail);Iu mode PDP context act fail (rejected by GGSN);Iu mode PDP context act fail(APN Restriction);Iu mode PDP context act fail(Ge fail);Iu mode PDP context act fail(insufficient net resources);Iu mode PDP context act fail(missing or unknown APN);Iu mode PDP context act fail(service not supported);Iu mode PDP context act fail(service unsubscribed);Iu mode PDP context act fail(unknown PDP addr or type);Iu mode PDP context act fail(unspecific reason);Iu mode PDP context act fail(user authentication fail);Iu mode PDP context act request times per subscriber @BH;Iu mode PDP context sec act;Iu mode PDP context sec act fail(Ge fail);Iu mode PDP context sec act fail(Unspecified Reason);Iu mode PDP context sec act fail(net resource insufficient);Iu mode PDP context sec act fail(rejected by GGSN);Iu mode PDP context sec act fail(unknown PDP context);Iu mode PDP context sec act reject;Iu mode PDP ctx act fail (Operator Determined Barring);Iu mode PDP ctx sec act fail (Operator Determined Barring);Iu mode active One Tunnel PDP Success;Iu mode active One Tunnel PDP fail;Iu mode active One Tunnel PDP reject(CAMEL);Iu mode active One Tunnel PDP reject(GTP Versions);Iu mode active Two Tunnel PDP Success;Iu mode active Two Tunnel PDP fail;Iu mode maximum MS init PDP context act;Iu mode secondary IPv4 PDP ctx act;Iu mode secondary IPv4 PDP ctx act success;Iu mode secondary IPv6 PDP ctx act;Iu mode secondary IPv6 PDP ctx act success;
MEASVALUE 21 72 93 13476 5492 7984 5 0 5 9540 783 13596 5568 5567 8028 59.047 8027 13594 0 6288830 8028 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 3 0 3427 41 0 0 162 0 0 452 0 1 1482 0.472 0 0 0 0 0 0 0 0 0 0 0 0 0 8028 4935 59 0 0 0 0





sanei05
 
Posts: 4
Joined: 17. November 2013 07:47
Operating System: Windows

Re: Element atrributes in case statement - php to xml

Postby JJ_Tagy » 09. December 2013 03:39

Not sure what exactly you are trying to do. Your SWITCH looks like it works (btw, you've got two GRANPERIODs in there). The reason nothing is displayed is because you don't ECHO any values. The reason you see some of your data is because you echo it under your CHAR function. If that is where the problem is, it may not display correctly what you are trying to do because those objects will be arrays.

Just to test and see what you are looking at, I did this:
Code: Select all
<?php
//Initialize the XML parser
$parser=xml_parser_create();

//Function to use at the end of an element

//Function to use at the start of an element
function start($parser,$element_name,$element_attrs) {
  echo $element_name . ":<br/>";
  foreach ($element_attrs as $attr) {
    echo "&nbsp;&nbsp;" . $attr . "<br/>";
  }
  echo "<br/>";
}

function stop($parser,$element_name) {
  //echo "<br>";
}

//Function to use when finding character data
function char($parser,$data) {
  echo "&nbsp;&nbsp;" . $data . "<br/>";
}

//Specify element handler
xml_set_element_handler($parser,"start","stop");

//Specify data handler
xml_set_character_data_handler($parser,"char");

//Open XML file
$fp=fopen("record1.xml","r");

//Read data
while ($data=fread($fp,4096)) {
  xml_parse($parser,$data,feof($fp)) or
    die (sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
}

//Free the XML parser
xml_parser_free($parser);
?>


Here are my results:
Code: Select all
MEASCOLLECFILE:
  http://latest/nmc-omc/cmNrm.doc#measCollec
  http://www.w3.org/2001/XMLSchema-instance
  http://latest/nmc-omc/cmNrm.doc#measCollec schema\pmResultSchedule.xsd

   
FILEHEADER:
  32.435 V7.2
  Huawei

   
FILESENDER:
  USN

   
MEASCOLLEC:
  2013-12-01T00:00:00+04:00

   
   
MEASDATA:

   
MANAGEDELEMENT:
  USN_AR

   
MEASINFO:
  11854767

   
GRANPERIOD:
  PT3600S
  2013-12-01T01:00:00+04:00

   
REPPERIOD:
  PT3600S

   
MEASTYPES:

  MME-init PDN disconnection request Times;MME-init PDN disconnection success Times;PDN disconnect fail Times(#35 PTI already in use);PDN disconnect fail Times(#43 Unknown EPS bearer ctx);PDN disconnect fail Times(#49 Last PDN disconn not allowed);PDN disconnect fail Times(#95-111 Protocol err, unspec);PDN disconnect fail Times(#96 Invalid mandatory information);PDN disconnect request Times;PDN disconnect success Times;
   
MEASVALUE:
  USN_AR/Whole System:USN_AR

   
MEASRESULTS:

  0 0 0 0 0 0 0 0 0
   
   
   
MEASINFO:
  117440618

   
GRANPERIOD:
  PT3600S
  2013-12-01T01:00:00+04:00

   
REPPERIOD:
  PT3600S

   
MEASTYPES:

  Components sent by the node;Componets received by the node;Reject component received by the node;Reject component sent by the node;Return error component received by the node;Return error component sent by the node;Return result received ultilizations(not last);Return result ultilizations received by the node;Return result ultilizations sent by the node;Return result ultilizations sent(not last);
   
MEASVALUE:
  USN_AR/Whole System:USN_AR

   
MEASRESULTS:

  23839 2067 0 0 3235 1 0 19163 2065 0
   
   
   
MEASINFO:
  117440600

   
GRANPERIOD:
  PT3600S
  2013-12-01T01:00:00+04:00

   
REPPERIOD:
  PT3600S

   
MEASTYPES:

  Iu mode Foreign subscribers act PDP context accept;Iu mode Foreign subscribers act PDP context reject;Iu mode Foreign subscribers init PDP context act;Iu mode MS init IPv4 PDP ctx act;Iu mode MS init IPv4 PDP ctx act reject;Iu mode MS init IPv4 PDP ctx act success;Iu mode MS init IPv6 PDP ctx act;Iu mode MS init IPv6 PDP ctx act reject;Iu mode MS init IPv6 PDP ctx act success;Iu mode MS init PDP context Max act time delay;Iu mode MS init PDP context Mean act time delay;Iu mode MS init PDP context act;Iu mode MS init PDP context act reject;Iu mode MS init PDP context act reject with dynamic addr;Iu mode MS init PDP context act success;Iu mode MS init PDP context act success rate;Iu mode MS init PDP context act success with dynamic addr;Iu mode MS init PDP context act with dynamic addr;Iu mode MS init PDP context sec act success;Iu mode Ms PDP Context Total act time delay;Iu mode Ms PDP Context act complete Total times;Iu mode NET PDP context act fail;Iu mode NET PDP context act fail ((insufficient net resources));Iu mode NET PDP context act fail (DNS resolution fail);Iu mode NET PDP context act fail (Operator Determined Barring);Iu mode NET PDP context act fail (QoS negotiation fail);Iu mode NET PDP context act fail (missing or unknown APN);Iu mode NET PDP context act fail (rejected by GGSN);Iu mode NET PDP context act fail (service not supported);Iu mode NET PDP context act fail (service unsubscribed);Iu mode NET PDP context act fail (unknown PDP addr or type);Iu mode NET PDP context act fail (user authentication fail);Iu mode NET PDP context act fail(APN Restriction);Iu mode NET PDP context act fail(Ge fail);Iu mode NET PDP context act fail(RAB assignment fail);Iu mode NET PDP context act fail(Unspecified Reason);Iu mode Network init IPv4 PDP ctx act;Iu mode Network init IPv4 PDP ctx act success;Iu mode Network init IPv6 PDP ctx act;Iu mode Network init IPv6 PDP ctx act success;Iu mode Network init PDP context act;Iu mode Network init PDP context act succe
  ss;Iu mode Network init sec PDP context act;Iu mode Network init sec PDP context act success;Iu mode PDP context act fail (DNS resolution fail);Iu mode PDP context act fail (QoS negotiation fail);Iu mode PDP context act fail (RAB assignment fail);Iu mode PDP context act fail (rejected by GGSN);Iu mode PDP context act fail(APN Restriction);Iu mode PDP context act fail(Ge fail);Iu mode PDP context act fail(insufficient net resources);Iu mode PDP context act fail(missing or unknown APN);Iu mode PDP context act fail(service not supported);Iu mode PDP context act fail(service unsubscribed);Iu mode PDP context act fail(unknown PDP addr or type);Iu mode PDP context act fail(unspecific reason);Iu mode PDP context act fail(user authentication fail);Iu mode PDP context act request times per subscriber @BH;Iu mode PDP context sec act;Iu mode PDP context sec act fail(Ge fail);Iu mode PDP context sec act fail(Unspecified Reason);Iu mode PDP context sec act fail(net resource insufficient);Iu mode PDP context sec act fail(rejected by GGSN);Iu mode PDP context sec act fail(unknown PDP context);Iu mode PDP context sec act reject;Iu mode PDP ctx act fail (Operator Determined Barring);Iu mode PDP ctx sec act fail (Operator Determined Barring);Iu mode active One Tunnel PDP Success;Iu mode active One Tunnel PDP fail;Iu mode active One Tunnel PDP reject(CAMEL);Iu mode active One Tunnel PDP reject(GTP Versions);Iu mode active Two Tunnel PDP Success;Iu mode active Two Tunnel PDP fail;Iu mode maximum MS init PDP context act;Iu mode secondary IPv4 PDP ctx act;Iu mode secondary IPv4 PDP ctx act success;Iu mode secondary IPv6 PDP ctx act;Iu mode secondary IPv6 PDP ctx act success;
   
MEASVALUE:
  USN_AR/Whole System:USN_AR

   
MEASRESULTS:

  21 72 93 13476 5492 7984 5 0 5 9540 783 13596 5568 5567 8028 59.047 8027 13594 0 6288830 8028 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 3 0 3427 41 0 0 162 0 0 452 0 1 1482 0.472 0 0 0 0 0 0 0 0 0 0 0 0 0 8028 4935 59 0 0 0 0
   
   
   
   
FILEFOOTER:

   
MEASCOLLEC:
  2013-12-01T01:00:00+04:00
JJ_Tagy
 
Posts: 678
Joined: 30. January 2012 13:44
Operating System: Windows 10 Pro x64


Return to PHP

Who is online

Users browsing this forum: No registered users and 3 guests