Find duplicated XML Element Names (xPath with variable)

后端 未结 2 988
萌比男神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:50

    This cannot be done with a single XPath 1.0 expression (see this similar question I answered today).

    Here is a single XPath 2.0 expression (in case you can use XPath 2.0):

    /*/*[(for $n in name() 
          return count(/*/*[name()=$n]) 
          )
         >1
         ]
    

    This selects all elements that are children of the top element of the XML document and that occur more than once.

提交回复
热议问题