You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Anand Narasimhan <an...@cisco.com> on 2005/04/22 03:19:03 UTC

New to JXPath. Please help

Hi,
 
I am new to JXPath. I just read the user guide briefly. I have a few
questions. Please help.
 
The user guide says  "JXPath applies XPath expressions to graphs of objects
of all kinds: JavaBeans, Maps, Servlet contexts, DOM etc, including mixtures
thereof. "
 
1. Can I use JXPath to select nodes from a tree containing arbitrary data by
applying XPath expressions. If so what do I need to do, what classes do I
need to extend. Or my understanding of JXPath is completely
wrong and JXPath cannot be used for this purpose?
2. If I want to package JXPath binaries with a commercial product, are there
any licensing restrictions. What are they?
 
A bit more information on my tree model. My tree mode is very much similar
to the javax.swing.tree.DefaultTreeModel and the nodes are similar to
javax.swing.tree.DefaultMutableTreeNode. 
 
public class Tree
{
    Node root;
 
   public Node getRoot();
    ...
}
 
public class Node 
{
    String nodeName;
    Node parent;
    List children;
    MyClass userData;
}
 
 
Implementation of MyClass does not follow the Java Bean conventions. It
basically contains a hash map of attribute/value pairs and has setAttribute
and getAttribute method. It also has a setter and getter for each attribute.

 
For eg.
 
public class MyClass
{
    protected HashMap attributes
 
    public void setAttribute( String key, Object value );
    public Object getAttribute( String key );
}
 
public class MyClass1 extends MyClass
{
    public static final String NAME = "Name";
    public static final String IP_ADDRESS = "IP Address";
 
    public String getName ()
    {
        return (String) getAttribute( NAME );
    }
 
    public String getIpAddress()
    {
        return (String) getAttribute( IP_ADDRESS );
    }
}
 
So, If have a tree instance like
 
                              Root
                                 |
                                 |
     ----------------------------------------------
    |                    |                                |                |
                         X                             X1
                         |                                |
                  -----------                ----------
                |                |                |                |
                Y            Y2          Z1            Z2
 
 
I want use XPath to select node /Root/X/Y2    or  /Root/X/Y[@Name = 'xyz'].
Is this possible with JXPath.
 
Thanks
Anand
 
_________________________________________________________________
 
Anand Narasimhan
anandn@cisco.com