XPath: How to check if an attribute exists ?

XPath: How to check if an attribute exists ?

Asked on January 4, 2019 in XML.
Add Comment


  • 3 Answer(s)

    To check if the attribute exixts in xpath:

    //*[@foo]
    

         The user can use a more specific expression and with [@attributeName] can get all nodes that have the attribute.

    Answered on January 4, 2019.
    Add Comment

         The following XPath expression can be used,

    //*[boolean(@foo)]
    
    Answered on January 4, 2019.
    Add Comment

         The xpath to check if an attribute that exists, it will return count of node/child which have attribute foo,

    count(//*[@foo])
    
    Answered on January 4, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.