Re: Am I a doofus?
Brought to you by:
bs_php,
nigelswinson
From: Nigel S. <nig...@us...> - 2002-08-06 00:22:50
|
> I've noticed a lot of differences in migrating from v2.2 to v3.3. :o( > For instance, this was possible in v2.2: > > $myxpath = new xpath(); > $myroot = $myxpath->appendChild("","superroot"); Ah... all the functions like importFromString() and appendChild() now take an xml string rather than just a node name, so you need to do: $myroot = $myxpath->appendChild("","<superroot/>"); However I just tried this and it didn't work, because the super root hadn't been setup, so this is a bug for which I thank you kindly for reporting :o) I've just implemented a change so that you can do this now. You'll find it in CVS if you can't wait for the next release, or you would like to do some testing :o) > .. but not in v3.3. Furter, in v2.2 a query through evaluate() to an > unique xpath would produce a string, whereas v3.3 produces an array > There are workarounds for it, but none the less - I've had numerous > encounters of the odd kind to which I can seem to find no obvious solution. In having a closer look at the XPath spec, the "top level" syntactical element is an "Expr", which.... http://www.w3.org/TR/xpath#section-Introduction "which has one of the following four basic types: a.. node-set (an unordered collection of nodes without duplicates) b.. boolean (true or false) c.. number (a floating-point number) d.. string (a sequence of UCS characters) " Clearly the intention wasn't to break anyone's code, but in order to support XPath properly (in it's recursive nature), you could now get a string, a number, a boolean or a node set (an array) as the result from match()/evaluate(). So if you have an xpath expression that is designed to "match" a node, then it really matches a node set that contains only one node, and hence it comes back to you in an array :o( You could always build a wrapper round match() that would convert an array with one element into just one string if that would make migration easier? > Can anyone tell me if I can find documentation on the differences in > implementation? Or, preferably; different examples on usage? I'll be more than happy to show you how to do what you need to do with version 3, sadly there is no definitive differences document. We worked fairly hard to minimise any public interface differences, as we know how distruptive they are to your code, and I was under the impression that the differences were slight, but then perhaps not... You could view the cvs history (which is fairly lenghty between 2.2 and 3.2), or do a diff between the .php files, but sadly nothing better than that is on offer. > I suspect being a doofus, but I'd really like to get this sorted out. Not a doofus at all :o) Let me/us know if you need anymore bug fixes or usage hints. Nigel |