Java Reference
In-Depth Information
// This is the </Item> element
// the last thing we need
iif ( "Item" . equals ( s )) {
done = true
true ;
}
}
return
return NodeFilter . FILTER_ACCEPT ;
}
public
public int
int getWhatToShow () {
return
return NodeFilter . SHOW_ALL ;
}
public
public short
short startElement ( Element element ) {
iif ( itemCountReached ) {
return
return NodeFilter . FILTER_ACCEPT ;
}
String s = element . getTagName ();
iif ( ITEM_ID . equals ( element . getTagName ())) {
iif ( addItemId ( element . getNodeValue ())) {
itemCountReached = true
true ;
}
}
return
return NodeFilter . FILTER_ACCEPT ;
}
}
The parsing filter is called twice for each element: the startElement() method is called
when parsing of an element begins, and the acceptNode() method is called when parsing of
an element is finished. If the element in question should not be represented in the final DOM
document, one of those methods should return FILTER_SKIP . In this case, the startEle-
ment() method is used to keep track of how many items have been processed, and the ac-
ceptNode() method is used to determine whether the entire element should be skipped or
not. Note that the code must also keep track of the ending <Item> tag so as not to skip that.
Also notice that only elements of type ItemArray are skipped; the XML document has other
elements in it that should not be skipped.
To set up the input filter, the following code is used:
System . setProperty ( DOMImplementationRegistry . PROPERTY ,
"com.sun.org.apache.xerces.internal.dom.DOMImplementationSourceImpl" );
DOMImplementationRegistry registry =
Search WWH ::




Custom Search