How can I get JDOM/XPath to ignore namespaces?

后端 未结 4 1609
轮回少年
轮回少年 2021-01-18 19:35

I need to process an XML DOM, preferably with JDOM, where I can do XPath search on nodes. I know the node names or paths, but I want to ignore namespaces completely<

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 20:26

    I know this question is a little old, but for those viewing this later, you can override a few JDOM default classes to effectively make it ignore namespaces as well. You can pass your own JDOMFactory implementation to the SAXBuilder that ignores all Namespace values passed into it.

    Then override the SAXBuilder class and implement the createContentHandler method so that it returns a SAXHandler with a blank definition for the startPrefixMapping method.

    I haven't used this in a production setting so caveat emptor, but I have verified that it does work on some quick and dirty XML stuff I've done.

提交回复
热议问题