Android evaluateXPath匹配包含类名

如果是XPath的使用可以查看 https://blog.csdn.net/qq_34627002/article/details/83309209
今天说的 evaluateXPath是属于TagNode类中的方法,它包含类的写法 有所不同

// XPath包含多个类名是这样 
xPath.evaluate("//div[contains(@class,'s-top-left')]//a", dom, XPathConstants.NODESET);
// TagNode这样使用会报错
ns = node.evaluateXPath("//div[contains(@class,'s-top-left')]//li");

// 正确方法 
ns = node.evaluateXPath("//div['ddd' < @class]//li");

其实可以点击该方法进入看注释 ,注释中

  • data(//a['v' < @id])
  • 就说了包含类名的用法

    /**
         * Evaluates XPath expression on give node. 
    * * This is not fully supported XPath parser and evaluator. * Examples below show supported elements: * *
      *
    • //div//a
    • *
    • //div//a[@id][@class]
    • *
    • /body/*[1]/@type
    • *
    • //div[3]//a[@id][@href='r/n4']
    • *
    • //div[last() >= 4]//./div[position() = last()])[position() > 22]//li[2]//a
    • *
    • //div[2]/@*[2]
    • *
    • data(//div//a[@id][@class])
    • *
    • //p/last()
    • *
    • //body//div[3][@class]//span[12.2 *
    • data(//a['v' < @id])
    • *
    *
    * * @param xPathExpression * @return result of XPather evaluation. * @throws XPatherException */ public Object[] evaluateXPath(String xPathExpression) throws XPatherException { return new XPather(xPathExpression).evaluateAgainstNode(this); }

    你可能感兴趣的:(Android evaluateXPath匹配包含类名)