XMLFilter exception

Discussion in 'Java' started by Timo Nentwig, Feb 7, 2004.

  1. Timo Nentwig

    Timo Nentwig Guest

    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
     
    Timo Nentwig, Feb 7, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jeff
    Replies:
    0
    Views:
    1,556
  2. jeff
    Replies:
    3
    Views:
    1,726
    Scott
    Jun 26, 2003
  3. Timo Nentwig

    XMLFilter truncates XML

    Timo Nentwig, Feb 13, 2004, in forum: Java
    Replies:
    0
    Views:
    469
    Timo Nentwig
    Feb 13, 2004
  4. Jeff Calico
    Replies:
    2
    Views:
    1,236
    Joseph Kesselman
    Feb 22, 2006
  5. alasdair.d

    XMLFilter after Transforming

    alasdair.d, Mar 10, 2010, in forum: XML
    Replies:
    2
    Views:
    923
    alasdair.d
    Mar 11, 2010
Loading...

Share This Page