Jump to content

Help with SimpleXML


jimneely

Recommended Posts

Okay I am new to this so bare with me. I have been trying to suck in a XML file and echo out it's attributes.  Here is a example PHP code I am trying to use to do this. I need direction on how to make this work. PLEASE!

 

<?php

$xml=simplexml_load_file("Jim.xml");

echo $xml->MachineData->['timeStamp'] . "<br>";

echo $xml->MachineData[0]->['machineID'] . "<br>";

echo $xml->MachineData[0]->['lineID'] . "<br>";

echo $xml->stationName . "<br>";

echo $xml->partNumber . "<br>";

echo $xml->modelNumber . "<br>";

echo $xml->serialNumber . "<br>";

echo $xml->LotNumber . "<br>";

?>

 

 

 

Jim.xml

Link to comment
https://forums.phpfreaks.com/topic/285960-help-with-simplexml/
Share on other sites

MachineData is your outermost element so

$machineData = simplexml_load_file('jim.xml');
echo $machineData['timeStamp'].'<br>';
echo $machineData['machineID'].'<br>';
echo $machineData['lineID'].'<br>';

echo $machineData->TrackingData['stationName'] . '<br>';
// etc
Link to comment
https://forums.phpfreaks.com/topic/285960-help-with-simplexml/#findComment-1467842
Share on other sites

How you can figure this stuff out on your own in the future:

 

 

<?php
$xml = simplexml_load_file('Jim.xml');
// Check out the contents
print_r($xml);
?>

 

 

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [timeStamp] => 2014-02-04T23:59:52
            [machineID] => TM-N158
            [lineID] => M200
        )

    [TrackingData] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [stationName] => HousingHeight
                    [partNumber] => 3051006070
                    [modelNumber] =>
                    [serialNumber] => 14BMJ03570
                    [LotNumber] => 879066
                )

            [KanbanNo] => 0
            [Data] => SimpleXMLElement Object
                (
                )

        )

)
Link to comment
https://forums.phpfreaks.com/topic/285960-help-with-simplexml/#findComment-1467843
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.