<HTML><DIV class=bgcolor STYLE="background-color: ;"><DIV
align=left>Hi,</DIV>
<DIV align=left>I need for a help ..I don't know how to add an
element to the xml file,&nbsp; delete from the file or
edite&nbsp;name of any element..I'm using JBuilder..as
you&nbsp;know that dealing with it&nbsp;is so hard!</DIV>
<DIV align=left>&nbsp;</DIV>
<DIV align=left>this is my code</DIV>
<DIV align=left>package fina;<BR>import java.awt.*;<BR>import
javax.swing.*;<BR>import javax.swing.tree.*;<BR>import
javax.swing.event.*;<BR>import java.util.Iterator;<BR>import
java.util.List;<BR>import org.jdom.*;<BR>import
org.jdom.input.SAXBuilder;<BR>import java.io.File;<BR>import
java.awt.event.*;<BR>import
javax.swing.event.TreeSelectionEvent;<BR>import
javax.swing.tree.DefaultMutableTreeNode;</DIV>
<DIV align=left>&nbsp;public class XMLTreeViewer extends
JFrame<BR>implements TreeSelectionListener {</DIV>
<DIV align=left>&nbsp; //The JTree to display the XML<BR>private
JTree xmlTree;</DIV>
<DIV align=left>//The XML document to be output to the
JTree<BR>private Document xmlDoc;<BR>DefaultMutableTreeNode
tn;</DIV>
<DIV align=left>&nbsp; JButton AddButton = new
JButton();<BR>&nbsp; JTextField TextField = new
JTextField();<BR>&nbsp; JTextArea TextArea = new
JTextArea();</DIV>
<DIV align=left>&nbsp;</DIV>
<DIV align=left>public XMLTreeViewer(Document doc) {<BR>&nbsp;
super();<BR>&nbsp;//
WindowUtilities.setNativeLookAndFeel();<BR>&nbsp;
addWindowListener(new ExitListener());<BR>&nbsp; this.xmlDoc =
doc;<BR>&nbsp; setSize(600, 450);<BR>&nbsp; tn = new
DefaultMutableTreeNode("XML");<BR>&nbsp;
initialize();<BR>}</DIV>
<DIV align=left>private void initialize() {<BR>&nbsp; xmlTree =
new JTree();<BR>&nbsp;&nbsp;&nbsp;
xmlTree.setEditable(true);<BR>&nbsp;&nbsp;&nbsp;
AddButton.setBackground(SystemColor.inactiveCaptionText);<BR>&nbsp;&nbsp;&nbsp;
AddButton.setForeground(Color.black);<BR>&nbsp;&nbsp;&nbsp;
AddButton.setText("ADD");<BR>&nbsp;&nbsp;&nbsp;
AddButton.addMouseListener(new java.awt.event.MouseAdapter()
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void
mouseClicked(MouseEvent e)
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AddButton_mouseClicked(e);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}<BR>&nbsp;&nbsp;&nbsp; });</DIV>
<DIV align=left><BR>&nbsp;&nbsp;&nbsp;
TextField.setText("");<BR>&nbsp;&nbsp;&nbsp;
TextArea.setText("jTextArea1");<BR>&nbsp;&nbsp;&nbsp;
getContentPane().add(new JScrollPane(xmlTree),
BorderLayout.CENTER);<BR>&nbsp;&nbsp;&nbsp;
this.getContentPane().add(TextField,
BorderLayout.NORTH);<BR>&nbsp;&nbsp;&nbsp;
this.getContentPane().add(AddButton,
BorderLayout.SOUTH);<BR>&nbsp;&nbsp;&nbsp;
this.getContentPane().add(TextArea, BorderLayout.EAST);</DIV>
<DIV align=left>&nbsp;</DIV>
<DIV align=left>&nbsp;&nbsp;&nbsp;
processElement(xmlDoc.getRootElement(), tn);<BR>&nbsp; (
(DefaultTreeModel) xmlTree.getModel()).setRoot(tn);<BR>&nbsp;
addWindowListener(new java.awt.event.WindowAdapter()
{<BR>&nbsp;&nbsp;&nbsp; public void
windowClosing(java.awt.event.WindowEvent e)
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //release all the
resource<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; xmlTree =
null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tn =
null;<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; });<BR>&nbsp;
setVisible(true);</DIV>
<DIV align=left>&nbsp; //add Listener to Print to Screen the xml
tag selected\<BR>&nbsp;
xmlTree.addTreeSelectionListener(this);<BR>}</DIV>
<DIV align=left>public void valueChanged(TreeSelectionEvent evt)
{</DIV>
<DIV align=left>&nbsp;&nbsp; // Get all nodes whose selection
status has changed<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TreePath[]
paths = evt.getPaths();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
Print the last Path Component
selected<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(evt.getPath().getLastPathComponent());</DIV>
<DIV align=left>//print the full path from the selected
tag<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println(evt.getPath().toString());<BR>&nbsp;&nbsp;
}</DIV>
<DIV align=left><BR>private void processElement(Element el,
DefaultMutableTreeNode dmtn) {<BR>&nbsp; DefaultMutableTreeNode
currentNode =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; new
DefaultMutableTreeNode(el.getName());<BR>&nbsp; String text =
el.getTextNormalize();<BR>&nbsp; if ( (text != null) &amp;&amp;
(!text.equals(""))) {<BR>&nbsp;&nbsp;&nbsp; currentNode.add(new
DefaultMutableTreeNode(text));<BR>&nbsp; }</DIV>
<DIV align=left>&nbsp; Iterator children =
el.getChildren().iterator();<BR>&nbsp; while
(children.hasNext()) {<BR>&nbsp;&nbsp;&nbsp; processElement(
(Element) children.next(), currentNode);<BR>&nbsp; }<BR>&nbsp;
dmtn.add(currentNode);<BR>}</DIV>
<DIV align=left><BR>&nbsp; public static void main(String[]
args)throws Exception {</DIV>
<DIV align=left>&nbsp;&nbsp;&nbsp; SAXBuilder builder = new
SAXBuilder();<BR>&nbsp;&nbsp;&nbsp; Document doc =
builder.build("comp.xml");<BR>&nbsp;&nbsp;&nbsp; XMLTreeViewer
viewer = new XMLTreeViewer(doc);<BR>&nbsp;&nbsp;&nbsp;
viewer.addWindowListener(new java.awt.event.WindowAdapter()
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void
windowClosing(java.awt.event.WindowEvent
e)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{System.exit(0);}<BR>&nbsp;&nbsp; });</DIV>
<DIV align=left>&nbsp; }</DIV>
<DIV align=left>&nbsp;&nbsp; void
AddButton_mouseClicked(MouseEvent e)
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;
TextArea.setSize(20,20);<BR>&nbsp;&nbsp; TextArea.setText("An
element will be\n added..");<BR>&nbsp;&nbsp;
TextField.getText();<BR>&nbsp;&nbsp; Object
o=xmlTree.getLastSelectedPathComponent();<BR>&nbsp;&nbsp;
addObject(o);<BR>&nbsp; // String
s=xmlTree.getLastSelectedPathComponent().toString();</DIV>
<DIV align=left><BR>&nbsp; }</DIV>
<DIV align=left>&nbsp; public void addObject(Object child)
{<BR>&nbsp;&nbsp;&nbsp; DefaultMutableTreeNode
parentNode=null;<BR>&nbsp;&nbsp;&nbsp; TreePath
parentPath=xmlTree.getSelectionPath();<BR>&nbsp;&nbsp;&nbsp;
if(parentPath!=null){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
parentNode=(DefaultMutableTreeNode)(parentPath.getLastPathComponent());<BR>&nbsp;&nbsp;&nbsp;&nbsp;
addObject(parentNode, child, true);<BR>&nbsp;&nbsp;&nbsp;
}<BR>&nbsp;&nbsp;&nbsp; }</DIV>
<DIV align=left>&nbsp; public void
addObject(DefaultMutableTreeNode parentNode, Object
child,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
boolean b) {<BR>&nbsp; }<BR>}<BR></DIV>
<DIV align=left>//---------------------------------------</DIV>
<DIV align=left>package fina;<BR>import javax.swing.*;<BR>import
java.awt.*;</DIV>
<DIV align=left>/** A few utilities that simplify using windows
in Swing.<BR>&nbsp;*&nbsp; 1998-99 Marty Hall, <A
href="http://www.apl.jhu.edu/~hall/java/">http://www.apl.jhu.edu/~hall/java/</A><BR>&nbsp;*/</DIV>
<DIV align=left>public class WindowUtilities {</DIV>
<DIV align=left>&nbsp; /** Tell system to use native look and
feel, as in previous<BR>&nbsp;&nbsp; *&nbsp; releases. Metal
(Java) LAF is the default otherwise.<BR>&nbsp;&nbsp; */</DIV>
<DIV align=left>&nbsp; public static void setNativeLookAndFeel()
{<BR>&nbsp;&nbsp;&nbsp; try {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());<BR>&nbsp;&nbsp;&nbsp;
} catch(Exception e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Error setting native LAF: " +
e);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</DIV>
<DIV align=left>&nbsp; public static void setJavaLookAndFeel()
{<BR>&nbsp;&nbsp;&nbsp; try {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());<BR>&nbsp;&nbsp;&nbsp;
} catch(Exception e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Error setting Java LAF: " +
e);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</DIV>
<DIV align=left>&nbsp;&nbsp; public static void
setMotifLookAndFeel() {<BR>&nbsp;&nbsp;&nbsp; try
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");<BR>&nbsp;&nbsp;&nbsp;
} catch(Exception e) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
System.out.println("Error setting Motif LAF: " +
e);<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; }</DIV>
<DIV align=left>&nbsp; /** A simplified way to see a JPanel or
other Container.<BR>&nbsp;&nbsp; *&nbsp; Pops up a JFrame with
specified Container as the content pane.<BR>&nbsp;&nbsp;
*/</DIV>
<DIV align=left>&nbsp; public static JFrame
openInJFrame(Container
content,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int
width,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int
height,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
String
title,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Color bgColor) {<BR>&nbsp;&nbsp;&nbsp; JFrame frame = new
JFrame(title);<BR>&nbsp;&nbsp;&nbsp;
frame.setBackground(bgColor);<BR>&nbsp;&nbsp;&nbsp;
content.setBackground(bgColor);<BR>&nbsp;&nbsp;&nbsp;
frame.setSize(width, height);<BR>&nbsp;&nbsp;&nbsp;
frame.setContentPane(content);<BR>&nbsp;&nbsp;&nbsp;
frame.addWindowListener(new
ExitListener());<BR>&nbsp;&nbsp;&nbsp;
frame.setVisible(true);<BR>&nbsp;&nbsp;&nbsp;
return(frame);<BR>&nbsp; }</DIV>
<DIV align=left>&nbsp; /** Uses Color.white as the background
color. */</DIV>
<DIV align=left>&nbsp; public static JFrame
openInJFrame(Container
content,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int
width,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int
height,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
String title) {<BR>&nbsp;&nbsp;&nbsp;
return(openInJFrame(content, width, height, title,
Color.white));<BR>&nbsp; }</DIV>
<DIV align=left>&nbsp; /** Uses Color.white as the background
color, and the<BR>&nbsp;&nbsp; *&nbsp; name of the Container's
class as the JFrame title.<BR>&nbsp;&nbsp; */</DIV>
<DIV align=left>&nbsp; public static JFrame
openInJFrame(Container
content,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int
width,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
int height) {<BR>&nbsp;&nbsp;&nbsp; return(openInJFrame(content,
width,
height,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
content.getClass().getName(),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Color.white));<BR>&nbsp;
}<BR>}<BR>//----------------------------------------</DIV>
<DIV align=left>package fina;<BR>import java.awt.*;<BR>import
java.awt.event.*;</DIV>
<DIV align=left>/** A listener that you attach to the top-level
Frame or JFrame of<BR>&nbsp;*&nbsp; your application, so
quitting the frame exits the application.<BR>&nbsp;*&nbsp;
1998-99 Marty Hall, <A
href="http://www.apl.jhu.edu/~hall/java/">http://www.apl.jhu.edu/~hall/java/</A><BR>&nbsp;*/</DIV>
<DIV align=left>public class ExitListener extends WindowAdapter
{<BR>&nbsp; public void windowClosing(WindowEvent event)
{<BR>&nbsp;&nbsp;&nbsp; System.exit(0);<BR>&nbsp;
}<BR>}<BR></DIV>
<DIV align=left>thank you ..</DIV>
<DIV align=left>Bassam</DIV>
<DIV align=left>&nbsp;</DIV></DIV></HTML>
<DIV>________________________________</DIV>
<DIV>Free POP3 Email from <a href="http://www.gawab.com"
target="_blank">www.gawab.com</a></DIV>
<DIV>Sign up NOW and get your account @gawab.com!!</DIV>