Handling namespaces during parsing
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
class SampleOfNamespacePrefixes extends DefaultHandler {
private Map namespaceMapping = new HashMap();
public void startPrefixMapping(String prefix, String uri) throws SAXException {
namespaceMapping.put(uri, prefix);
}
public void endPrefixMapping(String prefix) throws SAXException {
Iterator i = namespaceMapping.keySet().iterator();
for (; i.hasNext();) {
String uri = (String) i.next();
String uriPrefix = (String) namespaceMapping.get(uri);
if (prefix.equals(uriPrefix)) {
namespaceMapping.remove(uri);
break;
}
}
}
}
Related examples in the same category