Handling namespaceless XML file with SAX
On the SAX handlers' function, 3 element name present:
void startElement(String uri,
String localName,
String qName,
Attributes atts)
throws SAXException
For example, when <foobar:test xmlns:foobar="http://example.com/foobar">
tag is seeked, SAX call startElement
function with following parameters:
uri | "http://example.com/foobar" |
---|---|
localName | "test" |
qName | "foobar:test" |
When handling the Namespaceless XML documents, only qName seems to be used. But old Java Runtime such as Android 1.5(?), only localName seems to be used.
J2SE 6 | Android 2.2 | Android 1.5 | |
uri | "" |
"" |
"" |
localName | "" |
"" |
"test" |
qName | "test" |
"test" |
"" |
Sourcecode for Android 2.2/1.5 is as following:
public void testSAX() throws Exception {
final TextView tv = new TextView(this);
ByteArrayInputStream input = new ByteArrayInputStream("<test></test>".getBytes());
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
parser.parse(input, new DefaultHandler() {
@Override
public void startElement(String uri, String localName,
String qName, Attributes attributes) throws SAXException {
System.out.println("uri: " + uri);
System.out.println("localName: " + localName);
System.out.println("qName: " + qName);
tv.setText(
"uri: " + uri + "\n" +
"localName: " + localName + "\n" +
"test: " + qName
);
super.startElement(uri, localName, qName, attributes);
}
});
setContentView(tv);
}