libxml-raku / LibXML-raku

Raku bindings to the libxml2 native library
Artistic License 2.0
11 stars 5 forks source link

XPath context with default namespace? #104

Closed vrurg closed 1 year ago

vrurg commented 1 year ago

Is it generally possible to register a namespace on XPath context with no prefix? Taking an SVG, for example:

my LibXML::XPath::Context $xc .= new: :node($svg);
$xc.registerNs(Str, $svg.namespaceURI);
$xc.findnodes('//g[@id="surface1"]').elems > 0; # True

Because currently the only way to get it working is to:

$xc.registerNs("svg", $svg.namespaceURI);
$xc.findnodes('//svg:g[@id="surface1"]').elems > 0; # True

I tried to remove definedness from registerNS prefix parameter, but then it fails deeper in libxml2 itself.

An example of what's expected couldbe IntelliJ XPathView+XSLT plugin where it automatically picks up the default NS for its context.

dwarring commented 1 year ago

LibXML doesn't seem to have any way of setting a default namespace for XPath queries.

I'm guessing that IntelliJ is using the javax.xml.xpath setNamespaceContext() method.

I agree that it'd be nice to have. But I think it'd need to be implemented in libxml2.

vrurg commented 1 year ago

Ok, no sense to have this opened then.

Thank you!