NamespaceContext and using namespaces with XPath

后端 未结 5 944
被撕碎了的回忆
被撕碎了的回忆 2020-12-01 13:10

Resolving an xpath that includes namespaces in Java appears to require the use of a NamespaceContext object, mapping prefixes to namespace urls and vice versa.

5条回答
  •  长情又很酷
    2020-12-01 13:27

    If you are using the Spring framework you can reuse their NamespaceContext implementation org.springframework.util.xml.SimpleNamespaceContext

    This is a similar answer like the one from Asaf Mesika. So it doesn't give you automatic a NamespaceContext based on your document. You have to construct it yourself. Still it helps you because it at least gives you an implementation to starts with.

    When we faced a similar problem, Both the spring SimpleNamespaceContext and the "Apache WebServices Common Utilities" worked. We wanted to avoid to the addition jar dependency on Apache WebServices Common Utilities and used the Spring one, because our application is Spring based.

提交回复
热议问题