xpath find if node exists

后端 未结 6 1465
我在风中等你
我在风中等你 2020-11-28 04:09

Using a xpath query how do you find if a node (tag) exists at all?

For example if I needed to make sure a website page has the correct basic structure like /html/bod

6条回答
  •  天涯浪人
    2020-11-28 04:23

    A variation when using xpath in Java using count():

    int numberofbodies = Integer.parseInt((String) xPath.evaluate("count(/html/body)", doc));
    if( numberofbodies==0) {
        // body node missing
    }
    

提交回复
热议问题