XMLFilter exception
From: Timo Nentwig (tcn_at_spamgourmet.com)
Date: 02/07/04
- Next message: M Wilson: "Problem with first java program"
- Previous message: TT \(Tom Tempelaere\): "Re: Exception in beans"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 07 Feb 2004 14:04:47 +0100
Hi!
I hacked a tiny XMLFilter in order to filter <script> elements. But it
throws the following exception (on certain input documents, not all and,
alas, I were not able to locate the problem):
org.dom4j.DocumentException: The node "org.dom4j.tree.DefaultElement@18e3e60
[Element: <HTML attributes: []/>]" could not be added to the branch "null"
because: Cannot add another element to this Document as it already has a
root element of: HTML Nested exception: The node
"org.dom4j.tree.DefaultElement@18e3e60 [Element: <HTML attributes: []/>]"
could not be added to the branch "null" because: Cannot add another element
to this Document as it already has a root element of: HTML
public class XmlFilter extends XMLFilterImpl
{
private final String name = "script";
private boolean remove = false;
public XmlFilter()
{
super();
}
public void startElement(String namespaceUri, String localName, String
qualifiedName, Attributes attributes) throws SAXException
{
if (remove = remove || localName.equalsIgnoreCase(name)) return;
super.startElement(namespaceUri, localName, qualifiedName, attributes);
}
public void characters(char[] ch, int start, int length) throws
SAXException
{
if (remove) return;
super.characters(ch, start, length);
}
public void endElement(String uri, String localName, String qName) throws
SAXException
{
if (remove = localName.equalsIgnoreCase(name)) return;
super.endElement(uri, localName, qName);
}
}
Can somebody help?
TIA
TImo
- Next message: M Wilson: "Problem with first java program"
- Previous message: TT \(Tom Tempelaere\): "Re: Exception in beans"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|