Android XML DOM Parsing when you have namespaces?

[亡魂溺海] 提交于 2019-12-06 14:36:24

问题


When you have xml nodes with namespaces like:

<ns:abc>

then

getElementsByTagName("abc");

fails, but

getElementsByTagName("ns:abc");

works. But the issue is I don't know what is the namespace prefix chosen. Also for me,

getElementsByTagNameNS("*", "abc");

and

getElementsByTagNameNS("http://abcnamespace.com", "abc");

both return null.

If device is of interest, I am using CM7 on Nook. I don't want to use SAX, any other clean way to read the node lists.


回答1:


DocumentBuilderFactory.setNamespaceAware(true) should fix your problem.



来源:https://stackoverflow.com/questions/7076149/android-xml-dom-parsing-when-you-have-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!