-->

Android XML DOM Parsing when you have namespaces?

2020-07-27 05:30发布

问题:

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.