ThomasWeinert/FluentDOM

Css selectors are case-sensetive

Closed this issue · 3 comments

I'm not sure if its a FluentDOM issue or not. I believe css selectors should be case-insensitive but the are not.

$fd = FluentDOM::QueryCss('<div></div>')
    ->find('DIV')
    ->text('Hello World!');
echo $fd->document->toHtml(); //returns <div></div> (symfony css converter)

That depends on the content type. You're loading XML and XML is case sensitive. Try loading it as HTML or set the content type before calling find().

Thanks, so do you mean I need to use the following?

$fd = FluentDOM::QueryCss('<div></div>','html')
    ->find('DIV')
    ->text('Hello World!');
echo $fd->document->toHtml(); //returns <div></div>

This leads to a complete html document:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><div>Hello World!</div></body></html>

Is there any way set the content type as "html fragment"?

It might be possible to implement now for the new PHP version. Here are new constants for the DOMDocument. I will look into that again. Older versions always add html and body tags to the document.

However you can just echo the $fd variable:

$fd = FluentDOM::QueryCss('<div></div>', 'html')
    ->find('DIV')
    ->text('Hello World!');
echo $fd;

Additionally you can save the outer HTML of the div element:

$fd = FluentDOM::QueryCss('<div></div>', 'html')->find('DIV');
$fd->text('Hello World!');
echo $fd->outerHtml();

Another possibility would be a special loader that only keeps the nodes inside the body tag.