XMLFilter exception

T

Timo Nentwig

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top