public void startElement(String namespaceURI,
String localName,
String qName,
Attributes atts) throws SAXException {
try {
flushText();
int len = atts.getLength();
serializer.startElement(namespaceURI,localName,getPrefix(qName),null);
// declare namespace events
for( int i=0; i< len; i++ ) {
String qname = atts.getQName(i);
if(qname.startsWith("xmlns"))
continue;
String prefix = getPrefix(qname);
serializer.getNamespaceContext().declareNamespace(
atts.getURI(i), prefix, true );
}
for( int i=0; i< prefixMap.size(); i+=2 ) {
String prefix = (String)prefixMap.get(i);
serializer.getNamespaceContext().declareNamespace(
(String)prefixMap.get(i+1),
prefix,
prefix.length()!=0 );
}
serializer.endNamespaceDecls(null);
// fire attribute events
for( int i=0; i< len; i++ ) {
// be defensive.
if(atts.getQName(i).startsWith("xmlns"))
continue;
serializer.attribute( atts.getURI(i), atts.getLocalName(i), atts.getValue(i));
}
prefixMap.clear();
serializer.endAttributes();
} catch (IOException e) {
throw new SAXException2(e);
} catch (XMLStreamException e) {
throw new SAXException2(e);
}
}
|