[JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

[JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

yaron kanza
Hello,

I need an XPath parser. That is, a tool that receives an XPath
expression and returns either an object tree that represents the
expression (DOM style) or a series of events (SAX style).

Is JXPath the right tool for parsing XPath expressions?
If not, what is the right tool for parsing XPath?

In the user's guide I found only examples showing how to use JXPath
for evaluating XPath expressions. I didn't find example showing how to
parse XPath.

Can someone please provide me more information on how to use JXPath
for parsing expressions?

Does someone have examples showing how to use JXPath as a parser?

Thank you,

Yaron Kanza
The University of Toronto, Canada

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

Dmitri Plotnikov
Yaron,

JXPath will do that for you.  It does compile expressions (use the
static method on JXPathContext) and returns a tree.
One nice feature of that three is that if you call toString() on any
subtree, it returns the XPath it represents.

- Dmitri

--- yaron kanza <[hidden email]> wrote:

> Hello,
>
> I need an XPath parser. That is, a tool that receives an XPath
> expression and returns either an object tree that represents the
> expression (DOM style) or a series of events (SAX style).
>
> Is JXPath the right tool for parsing XPath expressions?
> If not, what is the right tool for parsing XPath?
>
> In the user's guide I found only examples showing how to use JXPath
> for evaluating XPath expressions. I didn't find example showing how
> to
> parse XPath.
>
> Can someone please provide me more information on how to use JXPath
> for parsing expressions?
>
> Does someone have examples showing how to use JXPath as a parser?
>
> Thank you,
>
> Yaron Kanza
> The University of Toronto, Canada
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

yaron kanza
Hello Dmitri,

Thank you for the quick response.

I was looking at the API of JXPathContext and I found the method
static CompiledExpression compile(java.lang.String xpath).
However, I couldn't find methods to traverse the parsed tree in the
CompileExpression class. So, I don't see how the compile method helps
me.

For example, suppose that I compile an expression //a/b[c=2]/d. Then,
how do I get the tree that represents the expression---a tree whose
root represents a descendant-or-self axis, the child of the root
represents the node-name "a", etc?

It will help me a lot if you will explain to me how to get the tree
that represents the expression (or the root of it).

Thank you very much,

Yaron


On 8/5/05, Dmitri Plotnikov <[hidden email]> wrote:

> Yaron,
>
> JXPath will do that for you.  It does compile expressions (use the
> static method on JXPathContext) and returns a tree.
> One nice feature of that three is that if you call toString() on any
> subtree, it returns the XPath it represents.
>
> - Dmitri
>
> --- yaron kanza <[hidden email]> wrote:
>
> > Hello,
> >
> > I need an XPath parser. That is, a tool that receives an XPath
> > expression and returns either an object tree that represents the
> > expression (DOM style) or a series of events (SAX style).
> >
> > Is JXPath the right tool for parsing XPath expressions?
> > If not, what is the right tool for parsing XPath?
> >
> > In the user's guide I found only examples showing how to use JXPath
> > for evaluating XPath expressions. I didn't find example showing how
> > to
> > parse XPath.
> >
> > Can someone please provide me more information on how to use JXPath
> > for parsing expressions?
> >
> > Does someone have examples showing how to use JXPath as a parser?
> >
> > Thank you,
> >
> > Yaron Kanza
> > The University of Toronto, Canada
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

Dmitri Plotnikov
Yaron,

CompiledExpression is merely an interface.  If you cast it to the concrete
class JXPathCompiledExpression, you will be able to traverse the tree.

If you are using Eclipse, you can always select an interface, press
Control-T, and see all classes implementing that interface.  Same, if you
use Control-T on a class, you will see all subclasses.

- Dmitri


----- Original Message -----
From: "yaron kanza" <[hidden email]>
To: "Jakarta Commons Users List" <[hidden email]>;
<[hidden email]>
Sent: Friday, August 05, 2005 6:16 PM
Subject: Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?


Hello Dmitri,

Thank you for the quick response.

I was looking at the API of JXPathContext and I found the method
static CompiledExpression compile(java.lang.String xpath).
However, I couldn't find methods to traverse the parsed tree in the
CompileExpression class. So, I don't see how the compile method helps
me.

For example, suppose that I compile an expression //a/b[c=2]/d. Then,
how do I get the tree that represents the expression---a tree whose
root represents a descendant-or-self axis, the child of the root
represents the node-name "a", etc?

It will help me a lot if you will explain to me how to get the tree
that represents the expression (or the root of it).

Thank you very much,

Yaron


On 8/5/05, Dmitri Plotnikov <[hidden email]> wrote:

> Yaron,
>
> JXPath will do that for you.  It does compile expressions (use the
> static method on JXPathContext) and returns a tree.
> One nice feature of that three is that if you call toString() on any
> subtree, it returns the XPath it represents.
>
> - Dmitri
>
> --- yaron kanza <[hidden email]> wrote:
>
> > Hello,
> >
> > I need an XPath parser. That is, a tool that receives an XPath
> > expression and returns either an object tree that represents the
> > expression (DOM style) or a series of events (SAX style).
> >
> > Is JXPath the right tool for parsing XPath expressions?
> > If not, what is the right tool for parsing XPath?
> >
> > In the user's guide I found only examples showing how to use JXPath
> > for evaluating XPath expressions. I didn't find example showing how
> > to
> > parse XPath.
> >
> > Can someone please provide me more information on how to use JXPath
> > for parsing expressions?
> >
> > Does someone have examples showing how to use JXPath as a parser?
> >
> > Thank you,
> >
> > Yaron Kanza
> > The University of Toronto, Canada
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]






---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

yaron kanza
Dmitri,

In the JXPathCompiledExpression API, I could only find methods for
evaluating an expression. But I don't need to evaluate the expression.
I need to parse it.

When you use Xerces to parse XML, for example, you can create a
DocumentBuilder, use it to parse a document and then you receive a
Document object which is the root of the DOM tree:

DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse("myDocument.xml");
   
What is the equivalent to this in JXPath?

Thank you,

Yaron


Thank you

On 8/6/05, Dmitri Plotnikov <[hidden email]> wrote:

> Yaron,
>
> CompiledExpression is merely an interface.  If you cast it to the concrete
> class JXPathCompiledExpression, you will be able to traverse the tree.
>
> If you are using Eclipse, you can always select an interface, press
> Control-T, and see all classes implementing that interface.  Same, if you
> use Control-T on a class, you will see all subclasses.
>
> - Dmitri
>
>
> ----- Original Message -----
> From: "yaron kanza" <[hidden email]>
> To: "Jakarta Commons Users List" <[hidden email]>;
> <[hidden email]>
> Sent: Friday, August 05, 2005 6:16 PM
> Subject: Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?
>
>
> Hello Dmitri,
>
> Thank you for the quick response.
>
> I was looking at the API of JXPathContext and I found the method
> static CompiledExpression compile(java.lang.String xpath).
> However, I couldn't find methods to traverse the parsed tree in the
> CompileExpression class. So, I don't see how the compile method helps
> me.
>
> For example, suppose that I compile an expression //a/b[c=2]/d. Then,
> how do I get the tree that represents the expression---a tree whose
> root represents a descendant-or-self axis, the child of the root
> represents the node-name "a", etc?
>
> It will help me a lot if you will explain to me how to get the tree
> that represents the expression (or the root of it).
>
> Thank you very much,
>
> Yaron
>
>
> On 8/5/05, Dmitri Plotnikov <[hidden email]> wrote:
> > Yaron,
> >
> > JXPath will do that for you.  It does compile expressions (use the
> > static method on JXPathContext) and returns a tree.
> > One nice feature of that three is that if you call toString() on any
> > subtree, it returns the XPath it represents.
> >
> > - Dmitri
> >
> > --- yaron kanza <[hidden email]> wrote:
> >
> > > Hello,
> > >
> > > I need an XPath parser. That is, a tool that receives an XPath
> > > expression and returns either an object tree that represents the
> > > expression (DOM style) or a series of events (SAX style).
> > >
> > > Is JXPath the right tool for parsing XPath expressions?
> > > If not, what is the right tool for parsing XPath?
> > >
> > > In the user's guide I found only examples showing how to use JXPath
> > > for evaluating XPath expressions. I didn't find example showing how
> > > to
> > > parse XPath.
> > >
> > > Can someone please provide me more information on how to use JXPath
> > > for parsing expressions?
> > >
> > > Does someone have examples showing how to use JXPath as a parser?
> > >
> > > Thank you,
> > >
> > > Yaron Kanza
> > > The University of Toronto, Canada
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: [JXPath] How to use JXPath for Parsing (not Evaluating) XPath?

Dmitri Plotnikov
Yaron,

Sorry, I forgot that getExpression() is declared as protected. So, you
don't really have access to the tree unless you change that method from
protected to public. Perhaps you could make that change locally.

I hope this helps.

- Dmitri



--- yaron kanza <[hidden email]> wrote:

> Dmitri,
>
> In the JXPathCompiledExpression API, I could only find methods for
> evaluating an expression. But I don't need to evaluate the
> expression.
> I need to parse it.
>
> When you use Xerces to parse XML, for example, you can create a
> DocumentBuilder, use it to parse a document and then you receive a
> Document object which is the root of the DOM tree:
>
> DocumentBuilder builder = factory.newDocumentBuilder();
> Document doc = builder.parse("myDocument.xml");
>    
> What is the equivalent to this in JXPath?
>
> Thank you,
>
> Yaron
>
>
> Thank you
>
> On 8/6/05, Dmitri Plotnikov <[hidden email]> wrote:
> > Yaron,
> >
> > CompiledExpression is merely an interface.  If you cast it to the
> concrete
> > class JXPathCompiledExpression, you will be able to traverse the
> tree.
> >
> > If you are using Eclipse, you can always select an interface, press
> > Control-T, and see all classes implementing that interface.  Same,
> if you
> > use Control-T on a class, you will see all subclasses.
> >
> > - Dmitri
> >
> >
> > ----- Original Message -----
> > From: "yaron kanza" <[hidden email]>
> > To: "Jakarta Commons Users List" <[hidden email]>;
> > <[hidden email]>
> > Sent: Friday, August 05, 2005 6:16 PM
> > Subject: Re: [JXPath] How to use JXPath for Parsing (not
> Evaluating) XPath?
> >
> >
> > Hello Dmitri,
> >
> > Thank you for the quick response.
> >
> > I was looking at the API of JXPathContext and I found the method
> > static CompiledExpression compile(java.lang.String xpath).
> > However, I couldn't find methods to traverse the parsed tree in the
> > CompileExpression class. So, I don't see how the compile method
> helps
> > me.
> >
> > For example, suppose that I compile an expression //a/b[c=2]/d.
> Then,
> > how do I get the tree that represents the expression---a tree whose
> > root represents a descendant-or-self axis, the child of the root
> > represents the node-name "a", etc?
> >
> > It will help me a lot if you will explain to me how to get the tree
> > that represents the expression (or the root of it).
> >
> > Thank you very much,
> >
> > Yaron
> >
> >
> > On 8/5/05, Dmitri Plotnikov <[hidden email]> wrote:
> > > Yaron,
> > >
> > > JXPath will do that for you.  It does compile expressions (use
> the
> > > static method on JXPathContext) and returns a tree.
> > > One nice feature of that three is that if you call toString() on
> any
> > > subtree, it returns the XPath it represents.
> > >
> > > - Dmitri
> > >
> > > --- yaron kanza <[hidden email]> wrote:
> > >
> > > > Hello,
> > > >
> > > > I need an XPath parser. That is, a tool that receives an XPath
> > > > expression and returns either an object tree that represents
> the
> > > > expression (DOM style) or a series of events (SAX style).
> > > >
> > > > Is JXPath the right tool for parsing XPath expressions?
> > > > If not, what is the right tool for parsing XPath?
> > > >
> > > > In the user's guide I found only examples showing how to use
> JXPath
> > > > for evaluating XPath expressions. I didn't find example showing
> how
> > > > to
> > > > parse XPath.
> > > >
> > > > Can someone please provide me more information on how to use
> JXPath
> > > > for parsing expressions?
> > > >
> > > > Does someone have examples showing how to use JXPath as a
> parser?
> > > >
> > > > Thank you,
> > > >
> > > > Yaron Kanza
> > > > The University of Toronto, Canada
> > > >
> > > >
> ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail:
> [hidden email]
> > > > For additional commands, e-mail:
> [hidden email]
> > > >
> > > >
> > >
> > >
> > >
> ---------------------------------------------------------------------
> > > To unsubscribe, e-mail:
> [hidden email]
> > > For additional commands, e-mail:
> [hidden email]
> > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail:
> [hidden email]
> >
> >
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]