QueryPath Extract from DIV class

Posted on 2012-08-17
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
    LVL 25

    Accepted Solution

    by: could give this a whirl:

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

    echo $title;
    LVL 1

    Author Comment

    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

    LVL 1

    Author Closing Comment

    LVL 25

    Expert Comment

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

    Glad you got it working!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…
    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…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now