Home > Software design >  XPath to SVG element?
XPath to SVG element?

Time:06-18

Any idea which XPath leads to this:

<a >
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M14.707 6.293L20.414 12l-5.707 5.707-1.414-1.414L16.585 13H4v-2h12.585l-3.292-3.293 1.414-1.414z" 

I'm trying things like "//a[@]/svg or //a[@]/[local-name()=‚svg‘] but nothing works.

CodePudding user response:

Your second XPath is close in its recognition that svg is in a namespace.

Change

//a[@]/[local-name()=‚svg‘]

to

//a[@]/*[local-name()="svg"]

to select the svg element.

Alternatively, declare a namespace prefix and use it in the XPath rather than defeating namespaces with the local-name() hack. See How does XPath deal with XML namespaces?

  • Related