Disappointed In SimpleXML
So I'm a little disappointed in PHP5's SimpleXML object. Don't get me wrong, it works great for accessing XML, but it's terrible for deep manipulation. The biggest problem is that you can't append SimpleXMLElement objects to each other.
For instance, I was working on a little project tracker that would use all XML for storage. Here is the var_dump of my XML file.
object(SimpleXMLElement)#1 (1) {
["project"]=>
array(3) {
[0]=>
object(SimpleXMLElement)#4 (5) {
["idstring"]=>
string(10) "1180050874"
["name"]=>
string(22) "Example Project Bottom"
["created"]=>
string(19) "2007-05-24 17:57:29"
["modified"]=>
string(19) "2007-05-24 17:59:44"
["contact"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#5 (3) {
["name"]=>
string(10) "John Hobbs"
["title"]=>
string(12) "Project Lead"
["email"]=>
string(20) "j0hn@velvetcache.org"
}
[1]=>
object(SimpleXMLElement)#6 (3) {
["name"]=>
string(9) "Mom Hobbs"
["title"]=>
string(3) "Mom"
["email"]=>
string(19) "mom@velvetcache.org"
}
}
}
[1]=>
object(SimpleXMLElement)#3 (5) {
["idstring"]=>
string(10) "1180050874"
["name"]=>
string(19) "Example Project Top"
["created"]=>
string(19) "2007-05-24 17:57:29"
["modified"]=>
string(19) "2007-05-24 18:57:44"
["contact"]=>
array(2) {
[0]=>
object(SimpleXMLElement)#7 (3) {
["name"]=>
string(10) "John Hobbs"
["title"]=>
string(12) "Project Lead"
["email"]=>
string(20) "j0hn@velvetcache.org"
}
[1]=>
object(SimpleXMLElement)#8 (3) {
["name"]=>
string(9) "Mom Hobbs"
["title"]=>
string(3) "Mom"
["email"]=>
string(19) "mom@velvetcache.org"
}
}
}
[2]=>
object(SimpleXMLElement)#2 (5) {
["idstring"]=>
string(10) "1180050892"
["name"]=>
string(22) "Example Project Middle"
["created"]=>
string(19) "2007-05-24 18:45:06"
["modified"]=>
string(19) "2007-05-24 18:45:06"
["contact"]=>
object(SimpleXMLElement)#9 (3) {
["name"]=>
string(10) "John Hobbs"
["title"]=>
string(12) "Project Lead"
["email"]=>
string(20) "j0hn@velvetcache.org"
}
}
}
}
Long, I know. The point is that even though the structure looks pretty normal, you can't do this, in this case in a sort function:
$temp = $projects->project[0];
$projects->project[0] = $projects->project[2];
$projects->project[2] = $temp;
You get the error message: Warning: sortProjects() [function.sortProjects]: It is not yet possible to assign complex types to properties in /var/www/timetracker/index.php on line 63 Warning: sortProjects() [function.sortProjects]: It is not possible to assign complex types to nodes in /var/www/timetracker/index.php on line 63
That, my friends, is a bummer. You can't assign sub-elements into the tree. Bummer. Now I have to switch back to my normal MySQL.