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


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

Reply via email to