Hi Vlad

I'm CCing the dom4j-user list in case anyone else has a similar problem...

----- Original Message -----
From: "Vlad Nevzorov" <[EMAIL PROTECTED]>
> Hi James,
>
> I apologize for bothering you, but I can't resolve a problem. Maybe you
can
> give me advice.
>
> I need to remove a node from a org.dom4j.Document object. I use the code:
>
>             Node toRemove  = doc.selectSingleNode(tag);
>             if(toRemove != null)
>             {
>                 if(doc.remove(toRemove))
>                 {
>                         log("---> Node " + tag+ " removed");
>                 }
>                 else
>                 {
>                         log("---> Node " + tag+ " found, but not
removed");
>
>                 }
>             }
>         }
>
> And I always receive the diagnostics "found, but not removed". What is
> wrong? And how can I remove the node?
>
> Thanks,
> Vlad

The remove() method is intended to remove immediate children from a Branch
(Document or Element). So it will only work in the above code if "toRemove"
is the root element. So returning false should indicate that "toRemove" is
not an immediate child of the Document.


If you have a node which you wish to remove from its parent, whatever it may
be, then the detach() method is preferable, which will remove the node from
its immediate parent.

e.g.

    Node toRemove  = doc.selectSingleNode(tag);
    if(toRemove != null) {
        toRemove.detach();
    }

James



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
dom4j-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/dom4j-user

Reply via email to