<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1106" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV>
<DIV>I've only been using JDom for a little while... but here is test class that
you can run that shows how I've been doing it. Maybe a seasoned expert may
want to comment on whether my usage is appropriate...</DIV>
<DIV>-Eric</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT size=2>import org.jdom.Element;<BR>import
org.jdom.Document;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>public class xmlDocumentTest {</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> /**<BR> * create
the jdom test document<BR> *
<BR> * <?xml version="1.0" encoding="ISO-8859-1"
?><BR> *
<PersonalData><BR> *
<FirstName>fName</FirstName><BR>
*
<MiddleName>mName</MiddleName><BR>
* <LastName>lName</LastName><BR>
* </PersonalData><BR> *
<BR> * @param fName<BR> * @param
mName<BR> * @param lName<BR> *
@return<BR> */ <BR> public Document
buildSampleXml(String fName, String mName, String lName){</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> Element root = new
Element("PersonalData"); //</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> Element node1 = new
Element("FirstName");<BR>
node1.addContent(fName);<BR>
root.addContent(node1);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> Element node2 = new
Element("MiddleName");<BR>
node2.addContent(mName);<BR>
root.addContent(node2);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> Element node3 = new
Element("LastName");<BR>
node3.addContent(lName);<BR>
root.addContent(node3);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> // create the
document<BR> return new
org.jdom.Document(root);<BR> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> /**<BR> * parse the
jdom document to extract the data of interest<BR> *
@param doc<BR> * @return<BR> */
<BR> public String readDocument(Document doc){</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> StringBuffer
fullName = new StringBuffer();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> Element root =
doc.getRootElement();<BR>
fullName.append(root.getChildText("FirstName") + "
");<BR>
fullName.append(root.getChildText("MiddleName") + "
");<BR>
fullName.append(root.getChildText("LastName"));</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> return
fullName.toString();</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> }</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> /**<BR> * pass the
3 arguments to execute the creating and reading of the jdom
document<BR> * @param args<BR>
*/ <BR> public static void main(String[] args){</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> String fName =
args[0];<BR> String mName =
args[1];<BR> String lName =
args[2];</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> xmlDocumentTest o =
new xmlDocumentTest();<BR> Document
xml = o.buildSampleXml(fName, mName,
lName);<BR> String xmlString =
o.readDocument(xml);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2>
System.out.println(xmlString);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT size=2> }</FONT></DIV>
<DIV><FONT size=2></FONT> </DIV>
<DIV><FONT size=2><FONT size=2> </DIV></FONT>
<DIV><FONT face=Arial></FONT></FONT> </DIV></DIV>
<BLOCKQUOTE
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style="FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV
style="BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: black"><B>From:</B>
<A title=k_salil@yahoo.com href="mailto:k_salil@yahoo.com">salil
khanwalkar</A> </DIV>
<DIV style="FONT: 10pt arial"><B>To:</B> <A title=jdom-interest@jdom.org
href="mailto:jdom-interest@jdom.org">jdom-interest@jdom.org</A> </DIV>
<DIV style="FONT: 10pt arial"><B>Sent:</B> Saturday, July 05, 2003 8:20
AM</DIV>
<DIV style="FONT: 10pt arial"><B>Subject:</B> [jdom-interest] creating
files</DIV>
<DIV><BR></DIV>
<DIV>Hi,</DIV>
<DIV> </DIV>
<DIV>I am new to XML</DIV>
<DIV>I want to create a file which has the first,middle,last names of a
person.Then i want to read the file and take individual values of the
first,middle,last name. Can anybody suggest me how to create this kind of
a file.</DIV>
<DIV> </DIV>
<DIV>Thank You,</DIV>
<DIV>Salil Khanwalkar.</DIV>
<DIV> </DIV>
<P>
<HR SIZE=1>
Do you Yahoo!?<BR><A
href="http://pa.yahoo.com/*http://rd.yahoo.com/evt=1207/*http://promo.yahoo.com/sbc/">SBC
Yahoo! DSL</A> - Now only $29.95 per month!</BLOCKQUOTE></BODY></HTML>