void popNamespaces ( int elemDepth , ContentHandler saxHandler ) { while ( true ) { if ( m_nodeStack . isEmpty ( ) ) return ; MappingRecord map = ( MappingRecord ) ( m_nodeStack . peek ( ) ) ; int depth = map . m_declarationDepth ; if ( elemDepth < 1 || map . m_declarationDepth < elemDepth ) break ; /* the depth of the declared mapping is elemDepth or deeper * so get rid of it */ MappingRecord nm1 = ( MappingRecord ) m_nodeStack . pop ( ) ; // pop the node from the stack String prefix = map . m_prefix ; Stack prefixStack = getPrefixStack ( prefix ) ; MappingRecord nm2 = ( MappingRecord ) prefixStack . peek ( ) ; if ( nm1 == nm2 ) { // It would be nice to always pop() but we // need to check that the prefix stack still has // the node we want to get rid of. This is because // the optimization of essentially this situation: // <a xmlns:x="abc"><b xmlns:x="" xmlns:x="abc" /></a> // will remove both mappings in <b> because the // new mapping is the same as the masked one and we get // <a xmlns:x="abc"><b/></a> // So we are only removing xmlns:x="" or // xmlns:x="abc" from the depth of element <b> // when going back to <a> if in fact they have // not been optimized away. // prefixStack . pop ( ) ; if ( saxHandler != null ) { try { saxHandler . endPrefixMapping ( prefix ) ; } catch ( SAXException e ) { // not much we can do if they aren't willing to listen } } } } }
Pop or undeclare all namespace definitions that are currently declared at the given element depth or deepter .