elementDepth++;
stackTop++;
// push the stack
AttributesImpl a = attStack[stackTop];
if( a==null )
attStack[stackTop] = a = new AttributesImpl();
else
a.clear();
// since Attributes object is mutable, it is criticall important
// to make a copy.
// also symbolize attribute names
for( int i=0; i<atts.getLength(); i++ ) {
String auri = atts.getURI(i);
String alocal = atts.getLocalName(i);
String avalue = atts.getValue(i);
String aqname = atts.getQName(i);
// work gracefully with misconfigured parsers that don't support namespaces
if( auri==null )
auri="";
if( alocal==null || alocal.length()==0 )
alocal=aqname;
if( aqname==null || aqname.length()==0 )
aqname=alocal;
// <foo xsi:nil="false">some value</foo> is a valid fragment, however
// we need a look ahead to correctly handle this case.
// (because when we process @xsi:nil, we don't know what the value is,
// and by the time we read "false", we can't cancel this attribute anymore.)
//
// as a quick workaround, we remove @xsi:nil if the value is false.
if( auri=="http://www.w3.org/2001/XMLSchema-instance" && alocal=="nil" ) {
String v = avalue.trim();
if(v.equals("false") || v.equals("0"))
continue; // skip this attribute
}
// otherwise just add it.
a.addAttribute(
auri,
alocal,
aqname,
atts.getType(i),
avalue );