Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > XMLFilter exception

Reply
Thread Tools

XMLFilter exception

 
 
Timo Nentwig
Guest
Posts: n/a
 
      02-07-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XMLFilter after Transforming alasdair.d XML 2 03-11-2010 11:02 AM
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
SAX XMLReader, XMLFilter, ContentHandler and XMLWriter question Jeff Calico XML 2 02-22-2006 06:13 PM
XMLFilter truncates XML Timo Nentwig Java 0 02-13-2004 05:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57