Jump to content

desmod

New Members
  • Posts

    7
  • Joined

  • Last visited

desmod's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Interesting. When I do: $xaxis=array(); for ($i = 1; $i <= 3; $i++) { $chachg_time = $xml->xpath("//ns:BulkData[ns:Name='ChannelChangeHistory.{$i}.ChannelChangeTime']/ns:Value"); echo '<pre>' . print_r($chachg_time, true) . '</pre>'; $chachg_time = $chachg_time[0]; $xaxis[] = $chachg_time[0]; } In PHP 5.3 I get: Array ( [0] => SimpleXMLElement Object ( [0] => 2013-11-12T01:01:45.207Z ) ) Array ( [0] => SimpleXMLElement Object ( [0] => 2013-11-12T02:02:45.207Z ) ) Array ( [0] => SimpleXMLElement Object ( [0] => 2013-11-12T03:03:45.207Z ) ) In PHP 5.4 I get: Array ( [0] => SimpleXMLElement Object ( ) ) Array ( [0] => SimpleXMLElement Object ( ) ) Array ( [0] => SimpleXMLElement Object ( ) ) Also, when I do the code below in both, PHP 5.3 or PHP 5.4 $xaxis=array(); for ($i = 1; $i <= 3; $i++) { $chachg_time = $xml->xpath("//ns:BulkData[ns:Name='ChannelChangeHistory.{$i}.ChannelChangeTime']/ns:Value"); $chachg_time = $chachg_time[0]; echo '<pre>' .$chachg_time .'</pre>'; $xaxis[] = $chachg_time[0]; } I get the same result: 2013-11-12T02:10:00.153Z 2013-11-12T02:15:00.153Z 2013-11-12T02:20:00.153Z
  2. The array below worked fine in PHP 5.3 but it is returning empty results in PHP 5.4 What is causing it? This is the code I am using: $xaxis=array(); for ($i = 1; $i <= 3; $i++) { $chachg_time = $xml->xpath("//ns:BulkData[ns:Name='ChannelChangeHistory.{$i}.ChannelChangeTime']/ns:Value"); $chachg_time = $chachg_time[0]; $xaxis[] = $chachg_time[0]; } In PHP 5.3, I get the expected result: Array ( [0] => SimpleXMLElement Object ( [0] => 6 ) ) Array ( [0] => SimpleXMLElement Object ( [0] => 6 ) [1] => SimpleXMLElement Object ( [0] => 5 ) ) Array ( [0] => SimpleXMLElement Object ( [0] => 6 ) [1] => SimpleXMLElement Object ( [0] => 5 ) [2] => SimpleXMLElement Object ( [0] => 3 ) ) However, after moving to server running PHP 5.4, I get the following empty results: Array ( [0] => SimpleXMLElement Object ( ) ) Array ( [0] => SimpleXMLElement Object ( ) [1] => SimpleXMLElement Object ( ) ) Array ( [0] => SimpleXMLElement Object ( ) [1] => SimpleXMLElement Object ( ) [2] => SimpleXMLElement Object ( ) )
  3. When using the following code: $yaxis=array(); $xaxis=array(); for ($i = 1; $i <= $number_of_entries; $i++) { $channel = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.{$i}.Channel']/ns:Value"); $channel = $channel[0]; $xaxis[]=$channel[0]; $apcount = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.{$i}.APcount']/ns:Value"); $apcount = $apcount[0]; $yaxis[]=$apcount[0]; } I get the following results for $xaxis and $yaxis arrays: print_r($xaxis); Array ( [0] => SimpleXMLElement Object ( [0] => 1 ) [1] => SimpleXMLElement Object ( [0] => 6 ) [2] => SimpleXMLElement Object ( [0] => 11 ) ) print_r($yaxis); Array ( [0] => SimpleXMLElement Object ( [0] => 3 ) [1] => SimpleXMLElement Object ( [0] => 8 ) [2] => SimpleXMLElement Object ( [0] => 6 ) ) What I am looking for is only the value of the nested array. Like this: print_r($xaxis); Array ( [0] => 1 [1] => 6 [2] => 11 ) print_r($yaxis); Array ( [0] => 3 [1] => 8 [2] => 6 ) How can I achieve this? Thanks for any help / suggestions!
  4. Sorry if my question was perhaps not clear. Lets say that I am getting XML data of cars sold on the end of each day and that looks like this: <?xml version = "1.0" encoding = "UTF-8"?> <ipdr:IPDRDoc xmlns:ipdr="http://www.ipdr.org/namespaces/ipdr" xmlns="urn:broadband-forum-org:ipdr:tr-232-1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:broadband-forum-org:ipdr:tr-232-1-0 tr-232-1-0-0-serviceSpec.xsd http://www.ipdr.org/namespaces/ipdr http://www.ipdr.org/public/IPDRDoc3.5.1.xsd" docId="74697373-6f74-7878-7878-746973736f74" creationTime="2013-06-11T06:02:55.153Z" IPDRRecorderInfo="Car Collector" version="3.5.1"> <ipdr:IPDR xsi:type="CarDataReport"> <BulkData> <Name>car.1.make</Name> <Value>Honda</Value> </BulkData> <BulkData> <Name>car.1.model</Name> <Value>Civic</Value> </BulkData> <BulkData> <Name>car.2.make</Name> <Value>Toyota</Value> </BulkData> <BulkData> <Name>car.2.model</Name> <Value>Camry</Value> </BulkData> <BulkData> <Name>car.3.make</Name> <Value>Ford</Value> </BulkData> <BulkData> <Name>car.3.model</Name> <Value>Escort</Value> </BulkData> </ipdr:IPDR > <ipdr:IPDRDoc.End count="1" endTime="2013-06-11T06:02:55.207Z"></ipdr:IPDRDoc.End> </ipdr:IPDRDoc> So lets say that I want to get the values for each Car Make/Model. If XML will always show me data for 3 cars than I can use for-loop and use condition <? for ($i = 1; $i <= 3; $i++){ $car_make = $xml->xpath("//ns:BulkData[ns:Name='car.{$i}.make']/ns:Value"); $car_make = $car_make[0]; $car_model = $xml->xpath("//ns:BulkData[ns:Name='car.{$i}.model']/ns:Value"); $car_model = $car_model[0]; echo $car_make'. .'$car_model'. <br> .'; } ?> But since my XML will show me different number of cars, the script above will not work. So far I came with this workaround. I just put some high number that I know it will not be exceeded and than break the loop when $car_model value is empty. I was just hoping there is more elegant solution to my problem. <? for ($i = 1; $i <= 1000; $i++){ $car_make = $xml->xpath("//ns:BulkData[ns:Name='car.{$i}.make']/ns:Value"); $car_make = $car_make[0]; $car_model = $xml->xpath("//ns:BulkData[ns:Name='car.{$i}.model']/ns:Value"); $car_model = $car_model[0]; if ($car_model == ""){ break; } else { echo $car_make'. .'$car_model'. <br> .'; } } ?>
  5. Currently I am able to use for-loop to get values for each pair of Channel and APcount because I know how many pairs are sent in XML. The "ResultNumberOfEntries" gives me that value and all is good. The question I have is, how would I be able to use for-loop if the ResultNumberOfEntries is not passed. Here is my code that works fine as long as ResultNumberOfEntries is known. <? $feed = file_get_contents("test.xml"); $xml = new SimpleXmlElement($feed); $xml->registerXPathNamespace("ns", "urn:broadband-forum-org:ipdr:tr-232-1-0"); $number_of_entries = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.ResultNumberOfEntries']/ns:Value"); $number_of_entries = $number_of_entries[0]; for ($i = 1; $i <= $number_of_entries; $i++) { $channel = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.{$i}.Channel']/ns:Value"); $channel = $channel[0]; $apcount = $xml->xpath("//ns:BulkData[ns:Name='InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.{$i}.APcount']/ns:Value"); $apcount = $apcount[0]; echo $channel.' : '.$apcount; echo "<br />"; } ?> Here is the test.xml file: <?xml version = "1.0" encoding = "UTF-8"?> <ipdr:IPDRDoc xmlns:ipdr="http://www.ipdr.org/namespaces/ipdr" xmlns="urn:broadband-forum-org:ipdr:tr-232-1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:broadband-forum-org:ipdr:tr-232-1-0 tr-232-1-0-0-serviceSpec.xsd http://www.ipdr.org/namespaces/ipdr http://www.ipdr.org/public/IPDRDoc3.5.1.xsd" docId="74697373-6f74-7878-7878-746973736f74" creationTime="2013-06-11T06:02:55.153Z" IPDRRecorderInfo="IPDR Collector" version="3.5.1"> <ipdr:IPDR xsi:type="BulkDataReport"> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.ResultNumberOfEntries</Name> <Value>3</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.1.Channel</Name> <Value>1</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.1.APcount</Name> <Value>3</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.2.Channel</Name> <Value>6</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.2.APcount</Name> <Value>8</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.3.Channel</Name> <Value>11</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.LANDevice.1.WLANConfiguration.X_181BEB_ChannelDiagnostics.Result.3.APcount</Name> <Value>6</Value> </BulkData> </ipdr:IPDR > <ipdr:IPDRDoc.End count="1" endTime="2013-06-11T06:02:55.207Z"></ipdr:IPDRDoc.End> </ipdr:IPDRDoc> This is the result I am expecting: 1 : 3 6 : 8 11 : 6
  6. Hello, I am going crazy trying to get the element values from XML file which contains elements with namespaces. Here is the XML file (test.xml) <?xml version = "1.0" encoding = "UTF-8"?> <ipdr:IPDRDoc xmlns:ipdr="http://www.ipdr.org/namespaces/ipdr" xmlns="urn:broadband-forum-org:ipdr:tr-232-1-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:broadband-forum-org:ipdr:tr-232-1-0 tr-232-1-0-0-serviceSpec.xsd http://www.ipdr.org/namespaces/ipdr http://www.ipdr.org/public/IPDRDoc3.5.1.xsd" docId="74697373-6f74-7878-7878-746973736f74" creationTime="2013-06-11T05:52:55.153Z" IPDRRecorderInfo="IPDR Collector" version="3.5.1"> <ipdr:IPDR xsi:type="BulkDataReport"> <OUI>124BEB</OUI> <ProductClass>BGW</ProductClass> <SerialNumber>1234567890</SerialNumber> <Suspect>1</Suspect> <BulkData> <Name>InternetGatewayDevice.DeviceInfo.UpTime</Name> <Value>1449</Value> </BulkData> <BulkData> <Name>InternetGatewayDevice.ManagementServer.URL</Name> <Value>www.somesite.com</Value> </BulkData> </ipdr:IPDR > <ipdr:IPDRDoc.End count="1" endTime="2013-06-11T05:52:55.207Z"></ipdr:IPDRDoc.End> </ipdr:IPDRDoc> I am trying to get element values for BulkData Here is the code I am using and having problem with: $cpe = simplexml_load_file('test.xml'); $sxe=new SimpleXMLElement($cpe); $sxe->registerXPathNamespace('ipdr','http://www.ipdr.org/namespaces/ipdr'); $result0=$sxe->xpath('ipdr:IPDR->BulkData[0]')->Value; $result1=$sxe->xpath('ipdr:IPDR->BulkData[1]')->Value; echo $result0 ' <br> ' $result1; The result I am looking for should be : 1449 www.somesite.com Thanks for any help you can offer.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.