2009年8月12日水曜日

SimpleXPath

PHP's SimpleXML, although deficient when it comes to parsing tags within CDATA --

<div>Hello<em>World</em></div> is found to have "World" emitted and "Hello" be put into CDATA.

-- and interpreting invokation parameters --

simplexml_load_string( $xml, null, LIBXML_NOENT ) does nothing to disregard 'erroroneous entities' in <a href="my.php?a=1&b=2"> (&b is considered an entity and expected as &b;)

-- well although deficient in these subjects, is still useful since it provides subtree-accessbility via Xpath - in a simplified form.

Task: find all Div-tags that belong to class "foo".
Xpath (2.0) does it like this:

//div[@class="foo"]

This works error-free and result-free also in SimpleXML's Xpath implementation. However, this:

//div[contains(@class,"foo")]

works as expected.

Thanks to dimuthu for poiting this out.

0 件のコメント:

コメントを投稿