Find all namespace declarations in an XML document - xPath 1.0 vs xPath 2.0

后端 未结 4 2068
渐次进展
渐次进展 2021-02-03 14:34

As part of a Java 6 application, I want to find all namespace declarations in an XML document, including any duplicates.

Edit: Per Martin\'s request, h

4条回答
  •  醉话见心
    2021-02-03 15:25

    I think this will get all namespaces, without any duplicates:

    for $i in 1 to count(//namespace::*) return 
    if (empty(index-of((//namespace::*)[position() = (1 to ($i - 1))][name() = name((//namespace::*)[$i])], (//namespace::*)[$i]))) 
    then (//namespace::*)[$i] 
    else ()
    

提交回复
热议问题