Domanda

Imagine that one were using JXPath as an access language into a tree that has certain nodes that represent collections that are impractically large or expensive to hold in memory - e.g.,

.../customers[id=12345]

where the customers are really in a database, and there are a bazillion of them. I don't need the full generality of all the queries that one could imagine - just a few kinds of well-indexed queries like this.

Is there a practical way to implement these using the customization capabilities of jxpath? If so, can you point me toward examples, relevant docs, etc?

È stato utile?

Soluzione

Have a look at the JXPath User's Guide. you can create an extension function that would take the query as a parameter.

public static NodeSet getCustomers(String query){
    List<Customer> l=getCustomersFromMyDatabase(query);
    BasicNodeSet bns=new BasicNodeSet();
    putCustomersIntoNodeSet(bns,l);
    return bns;
}

Your xpath would then look like

getCustomers('id=123')

You can have also a first parameter of type ExpressionContext, that can give you the context object if you need it, etc.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top