SimpleXML namespace and attributes of the tags?

Trying to put the data about the user of LiveJournal. Read online exampleusername.livejournal.com/data/foafupload it to SimpleXML:
$input_xml = simplexml_load_string(file_get_contents('http://exampleusername.livejournal.com/data/foaf'));



Since XML is unusual there, and with many namespaces, to retrieve a payload you need to load the descriptions of the namespaces. For example, get the name and date of birth of the user:
$person = $input_xml->children('http://xmlns.com/foaf/0.1/');
echo $person->Person->name.'<br>';
echo $person->Person->dateOfBirth;



Now I'm trying to extract the creation date of the blog, do the following:
$blog = $person->Person->weblog->children('http://www.livejournal.org/rss/lj/1.0/');



Now if you do a var_dump() the variable $blog, we see the following:
object(SimpleXMLElement)#4 (1) {
["@attributes"]=>
 array(2) {
["dateCreated"]=>
 string(19) "2008-12-15T18:00:10"
["dateLastUpdated"]=>
 string(19) "2012-03-16T09:49:22"
}
}



However, calling $blog->attributes() causes the error "Warning: var_dump(): Node no longer exists in /var/www/test.php on line 45", associative array $blog['dateCreated'] doesn't work either. What am I doing wrong?

Example parse XML file
October 8th 19 at 00:13
2 answers
October 8th 19 at 00:15
Solution
to this tag in the $tag, then try this:

$attr = $tag->attributes("lj", 1);
$dc = $attr["dateCreated"];
Changed this:
$blog = $children->Person->weblog->children('http://www.livejournal.org/rss/lj/1.0/');


This:
$blog = $children->Person->weblog;
$attr = $blog->attributes('lj', 1);
$created_at = (string) $attr['dateCreated'];


In the end everything turned out. Thank you! - Jessik commented on October 8th 19 at 00:18
health ) you're welcome)) - clementine_Trembl commented on October 8th 19 at 00:21
October 8th 19 at 00:17
The problem is that the attribute name has a ' @ ' symbol, the solution — to convert an object into an associative array, and access the attribute as array element:
$bug_blog=(array)$blog;
var_dump($bug_blog['@attributes']);
attributes is not the name of the attribute. The tag that I'm trying to "decode" it looks like this:
<foaf:weblog rdf:resource="http://ruslanleviev.livejournal.com/" lj:datecreated="2008-12-15T18:00:10" lj:datelastupdated="2012-03-16T09:49:22">
</foaf:weblog>

As you see, there in sight there is no attribute "attributes". What about dogs: as far as I remember refers to the protected-object properties. I.e. "@attributes" means non-public property $blog->attributes, in which are contained, I need the attributes that I'm trying to make.

The problem is that it is protected (protected) and directly read it not only through the $blog->attributes(), which, as I said above, for some reason returns an error, the node does not already exist. - Jessik commented on October 8th 19 at 00:20

Find more questions by tags PHP