Comments on XML_Tree & XML_Tree_Node
| From: | Alan Knowles | Date: | Sat, 12 Jan 2002 02:33:52 +0000 |
| Subject: | Comments on XML_Tree & XML_Tree_Node | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-3910@lists.php.net to get a copy of this message | ||
I was looking at a couple of uses for XML_Tree for a couple of modules I was writing, and thought I let you know of some
of the issues I had. - Some of these may be through lack of understanding of the class, but alot of it may be
that the XML_Tree is not really generic enough to cope with other Tree building mechanisums
The 2 mini-projects where
- building a php code -> xml structure, which for the most parts works. the idea was to thing
about a php->C code converter - but I dont have the time to look that heavily at present..
- building a navigation tree from a database, then dumping it out to a 'html' tree or sending it via xml/or serialize
to a php-gtk app.
one of the first issues I came across was trying to determine parentage of a child - it appears the only way to
do it would be to give the node an id, and start searching from the top. - obviosly a detail explaination of
how $path worked may have helped a little.
The passing of node objects around - I did attempt to write just with the Node object, but got embroilled in a
fight with the system sending copies around rather than references etc... - This seemed to add a level of complexity
that didnt help..
Bugs:
As far as I could see, there are still a few inherint bugs in the code that need fixing:
without testing - I could not see how it would deal with this syntax
(which is close to what is in the php manual xmldocbook)
<test>some text <function ref="xxxxx">data</function> more text</test>
It looks like it will have serious problems if it deals with text/cdata as a 'content' element, rather than being another child.
the dump/get function should urlencode its contents.
$out .= ' ' . $name . '="' . $value . '"';
to
$out .= ' ' . urlencode($name) . '="' . urlencode($value) . '"';
for the content it should
<![CDATA[ $content ]]>or slightly better - assuming you change the storage mechanism of content
foreach ($this->children as $child) {
if (is_object($child)) {
$out .= $child->get();
continue;
}
$out .= <![CDATA[ $content ]]>
}
}
adding an extra level field in get would allow you to do this.. (making prettier xml)
$out = str_repeat(" ",$level);
In the end, I ended up rewriting the whole thing, XML_Tree was a nice basis to start with.
most of the rewrite dealt with making an array of nodes, this obviosly lost alot of the
intelligence in the node, and moved it back to the tree, but it was more flexible to work
with.
$node->parent = 0
$node->id = 1
$node->title = "function"
$node->children = array(
2,3,4,array("sometext"),8); // where the numbers are id's of other nodes.
then the
$tree->nodes[$node->id] = $node;
The down and dirty hack is here..... http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/phpmole-ide/phpmole/phpconverter/XML_Tree_Node.class?rev=1.3&content-type=text/vnd.viewcvs-markup
regards
alan