[jdom-interest] Problem with ElementFilter
Bradley S. Huffman
hip at a.cs.okstate.edu
Mon Jun 24 13:20:33 PDT 2002
Charles.Robinson at abbott.com writes:
> Specifically I get the error report from ContentList
> org.jdom.IllegalAddException: Filter won't allow the org.jdom.Element
> '[Element: <view/>]' to be added to the list
> at org.jdom.ContentList$FilterList.add(ContentList.java:760)
> at java.util.AbstractList.add(AbstractList.java:84)
> at GenBO.main(GenBO.java:25)
> Filter won't allow the org.jdom.Element '[Element: <view/>]' to be added to
> the list
>
> when executing the following snippet of code
> SAXBuilder b = new SAXBuilder();
> File xmlFile = new File(args[0]);
> Document doc = b.build(xmlFile);
> Element root = doc.getRootElement();
> List t = root.getChildren("table");
> List v = root.getChildren("view");
> Iterator iterator = v.iterator();
> while (iterator.hasNext()) {
> // t.add(iterator.next());
> Element e = (Element)iterator.next();
> e = e.detach();
> t.add(e.clone());
> }
Instead of
List t = root.getChildren("table");
try
Element t = root.getChild("table");
What's happening is getChildren("table") is returning a list ("a view") of
only "table" elements, and the way filters with their canAdd method currently
work, only "table" elements would be allow to be added to this list.
Search the archives for "Simplifing Filters" for discussion on this. IMHO
this is one of those items that is causing more confusion than it's worth.
Brad
More information about the jdom-interest
mailing list