Search code examples
htmlperlxpathxml-libxml

XPath collect multiple attributes (html events)


I have a section of html code, and am trying to parse it via Perl's XML::LibXML module. I am trying to collect all the events within the html (onclick, onchange, onsubmit, etc), and thought XPath would be useful for identifying them. I know I can do

'//@onclick|//@onchange|//@onsubmit|...'

but was wondering if there's a way to avoid listing them, to ensure that no events are missed. The only idea I had was

'//@on*'

but that doesn't work.


Solution

  • Try doing this:

    '//@*[starts-with(name(), "on")]'
    

    The

    start-with()
    

    and

    name()
    

    are some Xpath functions, check http://www.w3.org/TR/xpath-functions/ & http://www.w3schools.com/xpath/xpath_functions.asp