4

I have elements like

<div class="a b c">...</div>

in my html. The xpath query //div[@class="a b c"] returns the correct nodelist in PHP 5.3.8. But the same query on PHP 5.2.2 doesn't return any nodes. What am I doing wrong ? . I have seen other questions of same type e.g. How can I match on an attribute that contains a certain string? and have tried stuff like :

//div[contains(concat(@class,' '),'a ') and contains(concat(' ',@class,' '),' b ') and 
            contains(concat(' ',@class),' c')]

but nothing seems to work. But it works perfectly well on PHP 5.3.8. What am I missing ?

Community
  • 1
  • 1
  • Are the doctype declarations the same in both environments? I have a vague recollection about HTML vs. XHTML. ...thought it MIGHT be worth a look. – Prpl_Ppl_Etr Feb 10 '12 at 22:03
  • I didn't understand which doctype are you referring to ? Is it the doctype of the HTML file ? It shouldn't matter because I am parsing the same file in both cases. BTW, if it helps in anyway : I am using WAMP server on Windows Vista 32bit. – user1202232 Feb 11 '12 at 15:40
  • is it a HTML-file, or XHTML-file? If it is the latter, you will possibly need to register the XHTML-namespace... xpath in PHP can really be a pain in the butt sometimes. – Marcus Olsson Feb 12 '12 at 09:46
  • 1
    I traced down the problem to the version of libxml being used by PHP. My PHP 5.2.2 installation is using libxml 2.6.26, whereas PHP 5.3.8 is using libxml 2.7.8. I tested the code on another host using PHP 5.2.2 and libxml 2.7.8 and the problem disappeared. Apparently there were some bugs in libxml 2.6.26. Hope this helps someone. This question can be considered closed. – user1202232 Feb 16 '12 at 06:39

0 Answers0