AlexGrim Posted October 1, 2009 Share Posted October 1, 2009 The problem is that i don't know how to access elements that have namespace prefixes. If you see the last element in this node, it uses a namespace "gd", and i'm used to accessing the elment name, but the namespace is throwing it off... Here's the XML: <?xml version='1.0' encoding='UTF-8'?> <feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:gContact='http://schemas.google.com/contact/2008' xmlns:batch='http://schemas.google.com/gdata/batch' xmlns:gd='http://schemas.google.com/g/2005'> .................. <entry> <id>http://www.google.com/m8/feeds/contacts/XXXXXXXXXXXXXXXX/base/0</id> <updated>2008-10-21T20:26:36.075Z</updated> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/contact/2008#contact'/> <title type='text'>Some Guy</title> <link rel='http://schemas.google.com/contacts/2008/rel#edit-photo' type='image/*' href='http://www.google.com/m8/feeds/photos/media/XXXXXXXXXXXXXXXX/0/XXXXXXXXXXXXXXXX'/> <link rel='self' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/XXXXXXXXXXXXXXXX/full/0'/> <link rel='edit' type='application/atom+xml' href='http://www.google.com/m8/feeds/contacts/XXXXXXXXXXXXXXXX/full/0/XXXXXXXXXXXXXXXX'/> <gd:email rel='http://schemas.google.com/g/2005#other' address='XXXXXXXXXXXXXXXX@gmail.com' primary='true'/> </entry> </feed> and here's the php: $xml = simplexml_load_string($xml); $a[] = array(); $n=0; foreach ($xml->entry as $entry) { $a[$n][0] = $entry->email['address']; $a[$n][1] = $entry->title; $n++; } Thanx Quote Link to comment Share on other sites More sharing options...
Mark Baker Posted October 1, 2009 Share Posted October 1, 2009 Without testing it out, something like: $xml = simplexml_load_string($xml); $namespaces = $xml->getNamespaces(true); foreach ($xml->entry as $entry) { $a[$n][0] = $entry->email['address']; $a[$n][1] = $entry->title; $a[$n][2] = $entry->title; $entryGD = $entry->children($namespaces['gd']); $entryGDAttributes = $entryGD->attributes(); $a[$n][3] = $entryGDAttributes['address']; $n++; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.