Re: Need help with PHP DOMXML - get_elements_by_tagname
From: MegaZone (newsREMOVE_at_THISmegazone.org)
Date: 11/25/03
- Next message: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Previous message: Terence: "Re: how can method of a parent get name of what subclass its being called from?"
- In reply to: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Next in thread: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Reply: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Nov 2003 01:34:24 GMT
Terence <tk.lists@fastmail.fm> shaped the electrons to say:
>I had a quick skim read of your post (as it was quite long) and it seems
>like you don't check to see if get_elements_by_tagname() is even
>returning at least one node.
In the example I did, no, I didn't bother with any real error
checking. I wrote it solely to illustrate the problem I'm having with
a much larger codebase. I stripped most of that stuff to try to keep
the sample from being monsterous. The overall codebase is a few
thousand lines.
>and also in your function you are using isset() to test if it is a node.
>not gonna work.
>
>if(!isset($nodeRef))
Actually that does work. If you do the lookup and get 0 results, then
set the node to the 0th element of the array, it is null. And the
isset check does catch passing in an unset node. I've had it happen
in the production code. But I'll check is_object and is_a, sounds
like they may do more appropriate checks.
>DOM can be laboursome. However, it is definately the best way to create
>XML data. DOM is fairly low-level in terms of describing a document,
I know, I've worked with DOM for a while. This codebase already
exists in other languages, the PHP version is more recent. One of the
over riding requirements is keeping the code structures of the various
implementations of the code similar. The Perl, ASP and CF
implementations all use DOM. I wrote the Perl code before we added
PHP as a supported platform. The Perl is using XML::LibXML for this,
which uses libxml2 - same as DOMXML. CF5 and ASP use MSXML, CF MX
uses the built in XML handler CF MX provides.
It was working in our 2.5.5 revision - the 2.6.0 revision restructured
the functions and introduced more pass-by-reference calls, and more
work from subnodes instead of always working from the root node. It
worked fine in all the other languages - but when the changes were
made to PHP, it stopped working. And it stems from this function.
Doing more digging since I posted (pretty much what I've been doing
all day), it looks like I'm going to have to change anyway. While
get_elements_by_tagname worked with xpath in some situations, the
response to one bug report at php.net indicates this has been changed
in newer versions of PHP and the method will *not* support xpath. The
reply indicated that if you want to use xpath, you need to explicitly
use the xpath methods. Unfortunate, since the other languages support
xpath in their equivalent methods (ASP/VB's SelectSingleNode, Perl's
findnodes, etc). But I think the simplest solution may be replacing
all the occurances of get_elements_by_tagname with the xpath
functions. At least all the occurances that break at this time.
Since the code is a sample framework that goes out to customers one of
the general requirements is to try not to depend on being too current
on the releases and trying to stick to libraries that are as common as
possible. XML handling is mandatory since the framework communicates
with a kiosk system that speaks XML only. Since the requirement for
XML was there, all of the configs and such are also stored in XML
since it is a nice format.
I'm looking forward to PHP5 since the XML support is a fundamental
feature. I only got back into PHP a few months ago (I had used it in
PHP3 days, and played with it in the PHP/FI days) when we added PHP to
our list of supported platforms. The initial port of Perl 2.5.5 to
PHP 2.5.5 actually went extremely smoothly. I was kind of surprised
to run into this trouble with 2.6.0 after that experience. There are
two main contexts for the framework - one is working, the other is not.
-MZ, RHCE #806199299900541, ex-CISSP #3762
-- <URL:mailto:megazoneatmegazone.org> Gweep, Discordian, Author, Engineer, me. "A little nonsense now and then, is relished by the wisest men" 508-755-4098 <URL:http://www.megazone.org/> <URL:http://www.eyrie-productions.com/> Eris
- Next message: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Previous message: Terence: "Re: how can method of a parent get name of what subclass its being called from?"
- In reply to: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Next in thread: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Reply: Terence: "Re: Need help with PHP DOMXML - get_elements_by_tagname"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|