How to convert TreePath object into an XML file?

P

Prakash

Hi,

I want to convert the selected fields of a JTree, into an XML file.
The getSelectionPaths() of JTree returns a TreePath[] object.
But how do I convert this into an XML file?
Is there any standard java API for that?

NOTE: The JTree itself is constructed from an XML file.......

Thanks in advance,
Prakash.
 
S

Salmo Bytes

Recurse down through the tree nodes
For each node, call a function that builds the
openning element. If that element has children,
continue recursion, else complete the current element.

public String mkXML(String xml, MyNodeType node)
{
xml += startNode(xml);
Enumeration nodes = node.children();
while(nodes.hasMoreElements())
{
subnode = (MyNodeType)node.nextElement();
xml += mkXML(ret, subnode);
}
xml += endNode(node);
return (xml);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,131
Latest member
IsiahLiebe
Top