Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- xml parsing issue
January 18, 2014, 9:54 am
rate this thread
short and simple piece of XML and I can't parse it, I have parsed xml in th
e past without issue but this I just can't sort for some reason.
<?xml version="1.0" encoding="UTF-8"?>
A print_r of the simplexml object it is loaded into:
[@attributes] => Array
[issuedAt] => 2014-01-18T04:00:00
All I want is that"issuedAt" time stamp, but it's an attribute not an eleme
nt. I have tried a foreach through @attributes and got nothing. I am even t
hinking of streaming it through an awk script (hosted on linux). I really
would like to avoid that and stay within PHP.
Any help appreciated.
Re: xml parsing issue
You're close, your simplexml object is but it is an object, not an
array. You have to call the attributes() function to get the array
of attributes, i.e.
foreach ($xml->attributes() as $name => $value)
echo $name . '="' . $value ."\"\n";
You can access just the 'issuedAt' attribute with
$name = 'issuedAt';
$value = $xml->attributes()->$name;
(Note: when using a non-default namespace you will have to specify the
namespace you're using, i.e.
Don't try to just cast the object as a string; you will get all kinds of
extra stuff if other attributes are added to your xml object.
Remove the "x" from my email address
- » How to locally install Wordpress, Ubuntu 8.10 , XAMPP already installed.
- — Previous thread in » PHP Scripting Forum