Zend_Dom_Query and attributes with spaces

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Zend_Dom_Query and attributes with spaces

Mon Zafra
Hi all,

How do I select a node with an attribute with spaces? This code:

require_once 'Zend/Dom/Query.php';
$val = 'foo bar';
$html = '<input type="text" value="' . $val . '" />';

$dom = new Zend_Dom_Query($html);
$res = $dom->query('input[value="' . $val . '"]');
echo(count($res));

returns 0. I need this to make my controller tests pass.


Regards,
-- Mon
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Dom_Query and attributes with spaces

weierophinney
Administrator
-- Mon Zafra <[hidden email]> wrote
(on Thursday, 16 October 2008, 03:50 AM +0800):

> Hi all,
>
> How do I select a node with an attribute with spaces? This code:
>
> require_once 'Zend/Dom/Query.php';
> $val = 'foo bar';
> $html = '<input type="text" value="' . $val . '" />';
>
> $dom = new Zend_Dom_Query($html);
> $res = $dom->query('input[value="' . $val . '"]');
> echo(count($res));
>
> returns 0. I need this to make my controller tests pass.

You need to use either a word match or a substring match:

    // word match:
    $res = $dom->query('input[value~="foo"]');

    // substring match:
    $res = $dom->query('input[value*="foo bar"]');

The first will look for "foo" anywhere in the attribute. The second
looks for "foo bar" anywhere in the attribute.

Strict comparisons often fail because, to be able to do word or
substring matches, we actually have to fudge a little and rewrite the
attribute values to app/prepend empty strings.

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Dom_Query and attributes with spaces

Mon Zafra
Thank you for the reply. However, using spaces with the word or substring selectors throws a fatal error.
For now, I'm using the word selector with the substring of the attribute value.

On Thu, Oct 16, 2008 at 4:27 AM, Matthew Weier O'Phinney <[hidden email]> wrote:
-- Mon Zafra <[hidden email]> wrote
(on Thursday, 16 October 2008, 03:50 AM +0800):
> Hi all,
>
> How do I select a node with an attribute with spaces? This code:
>
> require_once 'Zend/Dom/Query.php';
> $val = 'foo bar';
> $html = '<input type="text" value="' . $val . '" />';
>
> $dom = new Zend_Dom_Query($html);
> $res = $dom->query('input[value="' . $val . '"]');
> echo(count($res));
>
> returns 0. I need this to make my controller tests pass.

You need to use either a word match or a substring match:

   // word match:
   $res = $dom->query('input[value~="foo"]');

   // substring match:
   $res = $dom->query('input[value*="foo bar"]');

The first will look for "foo" anywhere in the attribute. The second
looks for "foo bar" anywhere in the attribute.

Strict comparisons often fail because, to be able to do word or
substring matches, we actually have to fudge a little and rewrite the
attribute values to app/prepend empty strings.

--
Matthew Weier O'Phinney
Software Architect       | [hidden email]
Zend Framework           | http://framework.zend.com/

Reply | Threaded
Open this post in threaded view
|

Re: Zend_Dom_Query and attributes with spaces

BullfrogBlues
In reply to this post by weierophinney
how would you query two attributes together?

I've tried quite a fwe variations:

<input type="text" value="somevalue'" />

$res = $dom->query('input[type="text" value="somevalue]');
$res = $dom->query('input[type="text", value="somevalue]');
$res = $dom->query('input[type="text"+value="somevalue]');
$res = $dom->query('input[type="text"][value="somevalue]');
etc...

Thanks,

Gerard

Matthew Weier O'Phinney-3 wrote
-- Mon Zafra <monzee@gmail.com> wrote
(on Thursday, 16 October 2008, 03:50 AM +0800):
> Hi all,
>
> How do I select a node with an attribute with spaces? This code:
>
> require_once 'Zend/Dom/Query.php';
> $val = 'foo bar';
> $html = '<input type="text" value="' . $val . '" />';
>
> $dom = new Zend_Dom_Query($html);
> $res = $dom->query('input[value="' . $val . '"]');
> echo(count($res));
>
> returns 0. I need this to make my controller tests pass.

You need to use either a word match or a substring match:

    // word match:
    $res = $dom->query('input[value~="foo"]');

    // substring match:
    $res = $dom->query('input[value*="foo bar"]');

The first will look for "foo" anywhere in the attribute. The second
looks for "foo bar" anywhere in the attribute.

Strict comparisons often fail because, to be able to do word or
substring matches, we actually have to fudge a little and rewrite the
attribute values to app/prepend empty strings.

--
Matthew Weier O'Phinney
Software Architect       | matthew@zend.com
Zend Framework           | http://framework.zend.com/
Reply | Threaded
Open this post in threaded view
|

Re: Zend_Dom_Query and attributes with spaces

umpirsky
Try:

$res = $dom->query('input[type="text"][value="somevalue]');

Regards,
Saša Stamenković


On Thu, Oct 1, 2009 at 11:19 PM, gerardroche <[hidden email]> wrote:

how would you query two attributes together?

I've tried quite a fwe variations:

<input type="text" value="somevalue'" />

$res = $dom->query('input[type="text" value="somevalue]');
$res = $dom->query('input[type="text", value="somevalue]');
$res = $dom->query('input[type="text"+value="somevalue]');
$res = $dom->query('input[type="text"][value="somevalue]');
etc...

Thanks,

Gerard


Matthew Weier O'Phinney-3 wrote:
>
> -- Mon Zafra <[hidden email]> wrote
> (on Thursday, 16 October 2008, 03:50 AM +0800):
>> Hi all,
>>
>> How do I select a node with an attribute with spaces? This code:
>>
>> require_once 'Zend/Dom/Query.php';
>> $val = 'foo bar';
>> $html = '<input type="text" value="' . $val . '" />';
>>
>> $dom = new Zend_Dom_Query($html);
>> $res = $dom->query('input[value="' . $val . '"]');
>> echo(count($res));
>>
>> returns 0. I need this to make my controller tests pass.
>
> You need to use either a word match or a substring match:
>
>     // word match:
>     $res = $dom->query('input[value~="foo"]');
>
>     // substring match:
>     $res = $dom->query('input[value*="foo bar"]');
>
> The first will look for "foo" anywhere in the attribute. The second
> looks for "foo bar" anywhere in the attribute.
>
> Strict comparisons often fail because, to be able to do word or
> substring matches, we actually have to fudge a little and rewrite the
> attribute values to app/prepend empty strings.
>
> --
> Matthew Weier O'Phinney
> Software Architect       | [hidden email]
> Zend Framework           | http://framework.zend.com/
>
>

--
View this message in context: http://www.nabble.com/Zend_Dom_Query-and-attributes-with-spaces-tp20000971p25706697.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Zend_Dom_Query and attributes with spaces

umpirsky
Ah, you tried, well, this ($res = $dom->query('input[type="text"][value="somevalue]');) is how it works with jQuery selectors.

Regards,
Saša Stamenković


On Fri, Oct 2, 2009 at 8:09 AM, Саша Стаменковић <[hidden email]> wrote:
Try:

$res = $dom->query('input[type="text"][value="somevalue]');

Regards,
Saša Stamenković



On Thu, Oct 1, 2009 at 11:19 PM, gerardroche <[hidden email]> wrote:

how would you query two attributes together?

I've tried quite a fwe variations:

<input type="text" value="somevalue'" />

$res = $dom->query('input[type="text" value="somevalue]');
$res = $dom->query('input[type="text", value="somevalue]');
$res = $dom->query('input[type="text"+value="somevalue]');
$res = $dom->query('input[type="text"][value="somevalue]');
etc...

Thanks,

Gerard


Matthew Weier O'Phinney-3 wrote:
>
> -- Mon Zafra <[hidden email]> wrote
> (on Thursday, 16 October 2008, 03:50 AM +0800):
>> Hi all,
>>
>> How do I select a node with an attribute with spaces? This code:
>>
>> require_once 'Zend/Dom/Query.php';
>> $val = 'foo bar';
>> $html = '<input type="text" value="' . $val . '" />';
>>
>> $dom = new Zend_Dom_Query($html);
>> $res = $dom->query('input[value="' . $val . '"]');
>> echo(count($res));
>>
>> returns 0. I need this to make my controller tests pass.
>
> You need to use either a word match or a substring match:
>
>     // word match:
>     $res = $dom->query('input[value~="foo"]');
>
>     // substring match:
>     $res = $dom->query('input[value*="foo bar"]');
>
> The first will look for "foo" anywhere in the attribute. The second
> looks for "foo bar" anywhere in the attribute.
>
> Strict comparisons often fail because, to be able to do word or
> substring matches, we actually have to fudge a little and rewrite the
> attribute values to app/prepend empty strings.
>
> --
> Matthew Weier O'Phinney
> Software Architect       | [hidden email]
> Zend Framework           | http://framework.zend.com/
>
>

--
View this message in context: http://www.nabble.com/Zend_Dom_Query-and-attributes-with-spaces-tp20000971p25706697.html
Sent from the Zend Framework mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: Zend_Dom_Query and attributes with spaces

BullfrogBlues

>Ah, you tried, well, this ($res =
>$dom->query('input[type="text"][value="somevalue]');) is how it works with
>jQuery selectors.
>
>Regards,
>Saša Stamenković

yep, it doesn't work, it looks like it should though.