Handling namespaceless XML file with SAX (2)
After last post, I found SAX namespace handling method can be changed with SAXParserFactory#setNamespaceAware() function.
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true); // Added
SAXParser parser = factory.newSAXParser();
This setting specify whether the parser supports XML namespaces or not and default value is false.
Following table is the result of namespace-less "<test>" tag.
| NamespaceAware | TRUE | FALSE |
|---|---|---|
| uri | "" |
"" |
| localName | "" |
"test" |
| qName | "test" |
"test" |
Note that: On Android 1.5, calling SAXParserFactory#setNamespaceAware() throws SAXNotSupportedException "The 'namespace-prefix' feature is not supported while the 'namespaces' feature is enabled.". We SHOULD USE newer Android OS.