MegaZone (zonereyrie) wrote,

  • Mood:
  • Music:


Learning a programming language under the gun isn't my favorite way of doing it. I like to have more time to read the PHP docs, but time is what I don't have. So I bulldoze on ahead, looking up answers when necessary. But I can't help but feel that I'm missing the bigger picture - the language structures, etc. Tonight I floundered about a bit figuring out XML DOM parsing with XPath in PHP. Turned out to be a lot easier than I thought - my first impression, from the docs, was that the XML DOM extension didn't do XPath! Just incomplete docs - I only just discovered that the online HTML version of the docs includes user submitted comments, which clear up a hell of a lot really. (I'd be using the PDF version of the docs that I downloaded.)

Still, it appears that you can't do things in one step in PHP that you can in Perl. For example:
$xpath = "//CurrencyTable/CurrencyShift[\@number='" . $currencyNumber . "']";

if (($domCurrency->findnodes($xpath))[0]->hasAttribute("name")) {

For PHP you have to break that statement down:
$test = $domCurrency->get_elements_by_tagname($xpath);
if ($test[0]->has_attribute("name")) {

PHP isn't happy if I try something like
if ($domCurrency->get_elements_by_tagname($xpath)[0]->has_attribute("name")) {

Please, correct me if I'm wrong. :-) It just seems like it doesn't allow you to directly reference an element from a method that returns an array.
  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded