QueryPath Extract from DIV class

Posted on 2012-08-17
Medium Priority
Last Modified: 2012-08-17
I'm working with a simple example to try to understand how QueryPath (DOM) handles elements in a page. Here is the example:

<div class="pup">
<img title="Test Title" src="myimage.jpg">

Open in new window

I've got this so far:

$testqp = htmlqp('test.html','body');
$header = $testqp->find('div[class="pup"]->img->title')->text();
echo $header;

Open in new window

How do I output the contents of the img/title (as seen above: "Test Title")?
Question by:kjenney
  • 2
  • 2
LVL 25

Accepted Solution

Kyle Hamilton earned 1680 total points
ID: 38306352
...you could give this a whirl:

$testqp = htmlqp('test.html','body');
$title = $testqp->find('div[class="pup"]->children("img")->attr("title")');

echo $title;

Author Comment

ID: 38306404
I was racking my brain trying to figure out why your solution didn't work. I played around with it and I got it to work. The Find method has to be closed and then chained to children. Thanks for the help!

$testqp = htmlqp('test.html','body');
$title = $testqp->find('div[class="pup"]')->children('img')->attr('title');
echo $title;

Open in new window


Author Closing Comment

ID: 38306410
LVL 25

Expert Comment

by:Kyle Hamilton
ID: 38306431
Cheers- that's funny, I was about to post that same change :)

Glad you got it working!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question