Database Reference
In-Depth Information
} else {
//keep other elements
super . startElement ( namespaceURI , localName , qname , attributes );
}
}
We drop any element that is named author . We achieve the drop simply by not
calling super.startElement .
We rename any element that is named color to colour . We do so by calling
super.startElement but replacing the element name.
We encapsulate any element that is named isbn (and its following siblings)
inside an element named reference . We do this by calling super.startElement
to start a new element, then calling super.startElement for the current element.
We keep any other element by simply calling super.startElement for the cur‐
rent element.
For the trigger to actually work, though, we must also have a matching endElement
method that balances the start and end of elements; otherwise, we will end up with a
document that is not well formed . Such a matching endElement method implementa‐
tion would look like:
@Override
public void endElement ( final String namespaceURI , final String localName ,
final String qname ) throws SAXException {
if ( localName . equals ( "author" )) {
//drop an element
} else if ( localName . equals ( "color" )) {
//rename an element
super . endElement ( namespaceURI , "colour" ,
qname . replace ( "color" , "colour" ));
} else if ( localName . equals ( "isbn" )) {
//encapsulate an element
super . endElement ( namespaceURI , localName , qname );
super . endElement ( namespaceURI , "reference" , "reference" );
} else {
//keep other elements
super . endElement ( namespaceURI , localName , qname );
}
}
Search WWH ::




Custom Search