XML/XSL

Hi,
I want to create a tree view(hierchical view) like in Explorer using XSL by reading the nodes(elements) from my xml file.How can I do this?.Can anyone suggest me a method?.In my XSL file,I've to handle for alignment,formating,color etc....
Once I create a tree,when I click on a node,its attributes has to be displayed on another frame.Is it possible to do this using XSL?.Can anyone help me out.Thanks in advance.
nahommAsked:
Who is Participating?
 
shlomoyConnect With a Mentor Commented:
using xml4j_2_0_15 (from IBM alphaworks) XML parser and using some Swing you can use the following snippet:


import com.ibm.xml.parsers.DOMParser;
import org.w3c.dom.Document;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import javax.swing.*;
import ui.DOMTree;

/** SimpleTreeView builds on GetParseTreeErrors
 *  to show how to build a JTree viewer from the DOM Document reference.
 */
public class SimpleTreeView extends JFrame {

    DOMParser parser;
    Errors errors;
   
    public static void main (String args[]) {

        if (args.length > 0) {
            String filename = args[0];

            try {
                SimpleTreeView frame = new SimpleTreeView(filename) ;
                frame.addWindowListener(new java.awt.event.WindowAdapter() {
                 public void windowClosing(java.awt.event.WindowEvent e) {
                     System.exit(0);
                 }
                });
                frame.setSize(300, 400);
                frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace(System.err);
                }
        }   }

    public SimpleTreeView (String filename) {
        super("SimpleTreeView: "+filename);
        try {
            parser = new DOMParser();
            errors = new Errors();
            parser.setErrorHandler(errors);
            parser.parse(filename);
            Document document = parser.getDocument();
            getContentPane().add(new JScrollPane(new DOMTree(document)));
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }

    class Errors implements ErrorHandler {
        public void warning(SAXParseException ex) {
            System.err.println(ex);
        }

        public void error(SAXParseException ex) {
            System.err.println(ex);
        }

        public void fatalError(SAXParseException ex) throws SAXException {
            System.err.println(ex);
        }
    }
}



Download XML4J at http://www.alphaworks.ibm.com/tech/xml4j
0
 
semuelCommented:
Hello there.

Shlomo, for 100 points you're giving your program ? sucker !  :-)

Semuel.
0
 
shlomoyCommented:
:-)
I'm for Open-Source.
0
All Courses

From novice to tech pro — start learning today.