Find duplicated XML Element Names (xPath with variable)

后端 未结 2 1014
萌比男神i
萌比男神i 2021-01-27 19:26

I\'m using XPATH 1.0 parsers alongside CLiXML in my JAVA project, I\'m trying to setup a CLiXML constraint rules file.

I would like to show an error if there are duplica

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-27 19:37

    Just try to get list of subnodes with appropriate path expression and check for duplicates in that list:

       XPathExpression xPathExpression = xPath.compile("//parentNode/*");
       NodeList children = (NodeList) xPathExpression.evaluate(config, XPathConstants.NODESET);
    
       for (int i = 0; i < children.getLength(); i++) {
       // maintain hashset of clients here and check if element is already there
       }
    

提交回复
热议问题