Skip to content

CSSSelector breaks on DOMDocument containing HTML elements with namespaces #12852

@jslegers

Description

@jslegers

PHPPowertools/DOM-Query is the first component of the PHPPowertools framework that has been released to the public. It's purpose is similar to that of technosophos/querypath but it's implementation is far more true to both jQuery's syntax and its semantics. For example, PHPPowertools/DOM-Query lets you do stuff like this :

// Add a span tag with classes 'icon' and 'icon-printer' to all buttons
$H->select('body')->select('button')->add('span')->addClass('icon icon-printer');

// Use a lambda function to set the data-val attribute of all gallery images
$H->select('.gallery li img')->attr('data-val', function( $i, $val) {
    return $i . " - " . $val->attr('class') . " - photo by Kelly Clark";
});

Under the hood, it uses symfony/CssSelector for converting _CSS selectors_ to _XPath queries_

What was still lacking until today, is proper support for HTML5. This has been solved by using Masterminds/html5-php's HTML loading and saving instead of native DOMDocument loading.

To allow Masterminds/html5-php and symfony/CssSelector to play well together, I needed to modify Masterminds/html5-php to prevent HTML elements from being generated with the http://www.w3.org/1999/xhtml namespace as the selectors generated by symfony/CssSelector failed to do their job.

Is support of namespaced HTML elements a missing feature in this component or is this merely an option that I overlooked?


See also PHPPowertools/DOM-Query#1 and Masterminds/html5-php#67.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions