----- Original Message -----
From: "Frank Sharpless" <[EMAIL PROTECTED]>
> Thanks James...
>
> I do have another question. Have you ever removed  a node, element from an
> xml file?

Yes many times ;-)

> I tried the document.remove(node) but it just returns false. Any
> Ideas?

Generally you remove a node from its parent. There's a helper method
detach() which will remove any node from its parent for you.

If you are calling remove() on the document object then this will only work
for comments or the root element which are immediate children of the
document. For nested elements which are descended from the root element
you'd need to call remove() on their immediate parent.

So maybe the detach() method might help, if you're not sure what the parent
is.

James

>
> Thanks again for your help!
>
> -Frank
>
>
> -----Original Message-----
> From: James Strachan [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 07, 2002 2:18 PM
> To: Frank Sharpless; Dom4j List (E-mail)
> Subject: Re: [dom4j-user] Adding element to document object
>
>
> Hi Frank
>
> Generally you'd do something like this...
>
> DocumentFactory factory = new DocumentFactory();
>
> Document doc = factory.createDocument();
> Element  pms = doc.addElement( "PMS" );
> Element importer = pms.addElement( "IMPORTER" );
> Element error = pms.addElement( "ERROR" );
> error.addText( "ERROR OCCURRED" );
>
> However there is a shorthand way of creating nested elements from via a
> subset of XPath as follows..
>
> Document doc = factory.createDocument();
> Element error = DocumentHelper.makeElement( doc, "/PMS/IMPORTER/ERROR" );
> error.addText( "ERROR OCCURRED" );
>
> I hope that helps
>
> James
> ----- Original Message -----
> From: "Frank Sharpless" <[EMAIL PROTECTED]>
> To: "Dom4j List (E-mail)" <[EMAIL PROTECTED]>
> Sent: Thursday, February 07, 2002 6:48 PM
> Subject: [dom4j-user] Adding element to document object
>
>
> > hello all..
> >
> > I am very new to dom4j. I have a quick question. If you want to add
> > element/value pairs to an existing xml document, what is the syntax? I
> tried
> > the following, but with no success:
> >
> > Element element = XMLDocument.addElement("//PMS/IMPORTER/ERROR", "ERROR
> > OCCURRED");
> >
> > Where PMS - root, Importer - element, Error - Node of Importer. "error
> > occurred" is the string of text to add to the value of the ERROR
element.
> >
> > Thanks for your help!
> >
> >
> > A. Frank Sharpless
> > Manager, Application Development
> > Paperhost.Com, Inc.
> > [EMAIL PROTECTED]
> > 770.998.9172.611
> >
> >
> > _______________________________________________
> > dom4j-user mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/dom4j-user
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com


_________________________________________________________
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