Come to the 2010 CMS Expo

QueryPath 2.0 Alpha 2

QueryPath Alpha 2 is now available.

The following major changes were made in Alpha 2:

  • The QueryPathImpl class has been re-named QueryPath. The QueryPath interface has been removed.
  • The file QueryPathImpl.php has been merged with the file QueryPath.php, and the interface has been removed from QueryPath.php
  • This version adds support for selectors as an argument to branch().
  • Bug Fix: When a selector that contained only an '#id' was executed and no such id was found, old matches were incorrectly returned. (Reported by Ryan Mahoney).

Only a few more changes are likely to come along before we switch from Alpha to Beta releases.

Please report bugs here: http://github.com/technosophos/querypath/issues

XML Namespace Issue in QueryPath?

Hi Matt,

Im doing this with QueryPath:

$url = url('http://blogs.cisco.com/rss/news/#', array('absolute' => TRUE));
foreach (qp($url, 'item') as $item) {
$title = $item->find('title')->text();
$link = $item->next('link')->text();
$descr = $item->next('description')->text();
$date = $item->next('dc:date')->text();

$out .= '<p>' . l($title, $link) . '</p><br><p>' . $descr . '<br>' . $date . '</p>';

}

It works fine as long as I dont try to pull the date...
but it wont work with the COLON in dc:date... how do we handle XML tags with Dublin Core namespace identifiers?

This was an issue in jQuery also that people seemed to fix by escaping the colon with \ - but that didnt work here for me.. tried to quote it all ways I could think of

Can you assist?

Old Jquery issue as reference:
http://dev.jquery.com/ticket/155

This is a very cool capability that I found last night while searching for Drupal Quiz information last night... excited to see where you take this!

Cheers,
Ken

Namespaces in QueryPath

This is one area where QueryPath is (by necessity) ahead of jQuery. QueryPath has full standards compliant support for XML namespaces. The only problem is... the standard is weird, and less than obvious.

Per the CSS 3 spec, namespace queries have to look like this:

dc|date

The colon is replaced with a vertical bar in a CSS 3 Selector.

So simply change your code to do this should work:

$date = $item->next('dc|date')->text();

You can see an example of this in a recent post (http://technosophos.com/content/reading-odt-files-querypath) or in the examples/ folder of the full QueryPath distribution. The Drupal QueryPath module also includes some examples that use namespaced queries to handle RDF data.

That one didnt work for me...

Hi Matt,

The deeper I dive into the Drupal hole... I see more and more of your name. So, I have to say thanks again - you are enabling some pretty cool stuff that I think will make the Internet a much better place.

Unfortunately, I had already found the page you referenced and tried that one... dc|date didnt work either (though it was safely ignored and page rendered).

Here is my code if you want to try it yourself... just a cut and paste of your example really.

$url = url('http://blogs.cisco.com/rss/news/#', array('absolute' => TRUE));
  foreach (qp($url, 'item') as $item) {
    $title = $item->find('title')->text();
    $link = $item->next('link')->text();
    $descr = $item->next('description')->text();
    $date = $item->next('dc|date')->text();
    $out .= '<p>' . l($title, $link) . '<hr  size=2px style="color:#8dbc56; padding:0px; margin:0px">';
    $out .= '</p><br><p>' . $descr . '<br>' . $date . '</p>';
    $out .= '<hr  size=2px style="color:#8dbc56; padding:0px; margin:0px">';
  }

Ken

Try this one.

I just tried this (minor tweaks from your code above, since I am testing outside of Drupal), and it works:

<?php
require 'QueryPath/QueryPath.php';
$out = '';
foreach (qp('http://blogs.cisco.com/rss/news/#', 'item') as $item) {
  $title = $item->find('title')->text();
  $link = $item->next('link')->text();
  $descr = $item->next('description')->text();
  $date = $item->next('dc|date')->text();
  $out .= '<p>' . $title .  $link . '<hr  size=2px style="color:#8dbc56; padding:0px; margin:0px">';
  $out .= '</p><br><p>' . $descr . '<br>' . $date . '</p>';
  $out .= '<hr  size=2px style="color:#8dbc56; padding:0px; margin:0px">';
}  
print $out;
?>

Notice that the dc|date stuff is the same. It gives me output like this:

<p>Rami Mazid, VP of Global Client Services and Operations, Cisco shares with you how Cisco technology supports a globally dispersed workforce, while Carina Reyes, manager, Operations, shares her experience as a working mother at Cisco.
</p><br>2009-06-26T12:07:00+00:00</p><hr  size=2px style="color:#8dbc56; padding:0px; margin:0px">

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.
  • Images can be added to this post.

More information about formatting options