I've often wondered that a simple & small API could be used to access
information from XML using just XPath to do all the work. Then XPath becomes
an alternative for a DOM API.

This only works for reading information so I'm not sure how useful this is
in general but I just thought I'd share my musings with the list to see what
others thought.

e.g imagine something like this...


/** evaluates XPath expressions */
public interface X {

    // iterate through the nodeset results of the expression
    public Iterator iterator( String expression );

    public String valueOf( String expression );

    public boolean test( String expression );

    // gets a new X for the given XPath expression
    public X eval( String expression );

    // getters & setters for variable, function & namespace contexts
    // go here, left out for brevity...
}

Then we could use it to do things like this...

X doc = ...;

// now lets use it...
Iterator iter =  doc.iterator( "//foo" );
while (iter.hasNext() ) {
    X foo = (X) iter.next();
    String name = foo.valueOf( "@name" );
    X bars = foo.eval( "bar" );
    if ( bars.test( "x[@p='23']" ) {
        ...
    }
}

To create the initial doc could be from an exisitng model, or via an XPath
expression. e.g.

// create an X from somewhere either via
X doc = new Xdom4j( aDocument );

// use an empty X to start with...
X x = X.create();
X doc = x.eval( "document('/a/b/c.xml' )" );


James


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


_______________________________________________
Jaxen-interest mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jaxen-interest

Reply via email to