[digester] using xpath to select nodes

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

[digester] using xpath to select nodes

Valerio
Hello,
i have this kind of xml i want to parse:
<pageclass name='news'>
<page pageid="33">
            <metadata name="title>
             a title
            </metadata>
            <metadata name="remoteURL">
            a url
           </metadata>
</page>
</pageclass>
<pageclass name='other'>
<page pageid="xx">
   ....
</page>
</pageclass>

So in the digester i have this code (only relevant part ):

digester.setRules(new ExtendedBaseRules());
digester.addObjectCreate("website/pageclass[@name='news']/page",
                Notizia.class.getName());

which doesn't work as I was supposing:  when I try to peek the object on the
stack, i get a NPE.
So the question is: does digester support that kind of xpath expressions to
select nodes?


--
To Iterate is Human, to Recurse, Divine
James O. Coplien, Bell Labs
(how good is to be human indeed)
Reply | Threaded
Open this post in threaded view
|

Re: [digester] using xpath to select nodes

Simon Kitching
On Thu, 2006-02-09 at 16:46 +0100, Valerio Schiavoni wrote:

> Hello,
> i have this kind of xml i want to parse:
> <pageclass name='news'>
> <page pageid="33">
>             <metadata name="title>
>              a title
>             </metadata>
>             <metadata name="remoteURL">
>             a url
>            </metadata>
> </page>
> </pageclass>
> <pageclass name='other'>
> <page pageid="xx">
>    ....
> </page>
> </pageclass>
>
> So in the digester i have this code (only relevant part ):
>
> digester.setRules(new ExtendedBaseRules());
> digester.addObjectCreate("website/pageclass[@name='news']/page",
>                 Notizia.class.getName());
>
> which doesn't work as I was supposing:  when I try to peek the object on the
> stack, i get a NPE.
> So the question is: does digester support that kind of xpath expressions to
> select nodes?

No. None of the rule-matching implementations support XPath expressions.

As this has been asked before, I've created a new FAQ entry; see the
last entry in this page:
  http://wiki.apache.org/jakarta-commons/Digester/FAQ

Regards,

Simon


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

Reply | Threaded
Open this post in threaded view
|

Re: [digester] using xpath to select nodes

craigmcc
On 2/9/06, Simon Kitching <[hidden email]> wrote:

>
> On Thu, 2006-02-09 at 16:46 +0100, Valerio Schiavoni wrote:
> > Hello,
> > i have this kind of xml i want to parse:
> > <pageclass name='news'>
> > <page pageid="33">
> >             <metadata name="title>
> >              a title
> >             </metadata>
> >             <metadata name="remoteURL">
> >             a url
> >            </metadata>
> > </page>
> > </pageclass>
> > <pageclass name='other'>
> > <page pageid="xx">
> >    ....
> > </page>
> > </pageclass>
> >
> > So in the digester i have this code (only relevant part ):
> >
> > digester.setRules(new ExtendedBaseRules());
> > digester.addObjectCreate("website/pageclass[@name='news']/page",
> >                 Notizia.class.getName());
> >
> > which doesn't work as I was supposing:  when I try to peek the object on
> the
> > stack, i get a NPE.
> > So the question is: does digester support that kind of xpath expressions
> to
> > select nodes?
>
> No. None of the rule-matching implementations support XPath expressions.


It would also likely require some pretty fundamental architectural changes,
since Digester uses a SAX parser underneath the covers (and never has access
to a data structure representing the entire document).  XPath queries seem
much more appropriate when you've got the whole DOM of the document to
examine.

Craig
Reply | Threaded
Open this post in threaded view
|

Re: [digester] using xpath to select nodes

Simon Kitching
On Thu, 2006-02-09 at 21:52 -0800, Craig McClanahan wrote:
>         No. None of the rule-matching implementations support XPath
>         expressions.
>
> It would also likely require some pretty fundamental architectural
> changes, since Digester uses a SAX parser underneath the covers (and
> never has access to a data structure representing the entire
> document).  XPath queries seem much more appropriate when you've got
> the whole DOM of the document to examine.

Well, I agree that supporting XPath in general is not possible with
Digester, which is fundamentally based on SAX while XPath is
fundamentally based on DOM.

However for the specific case in question, which is matching based on
attribute values, is it really impossible to provide that functionality
in some form? When the opening tag of the element is encountered, the
attributes are also provided, so I believe it's possible in principle to
fire  methods for rules based on attribute values while still using SAX.

I agree that adding it to the existing digester 1.x implementation is
not feasable because the existing Rules class API doesn't pass this
info; adding this would break all existing Rules classes which isn't
reasonable. However I don't see why a digester2 project couldn't
redesign things to make this possible. Am I missing something? I was
certainly planning on adding this sort of functionality to digester2 (if
I ever find time to resume work on it). In particular, I was interested
in looking at STX (http://stx.sourceforge.net/) rather than xpath as
inspiration, as I believe the STX expression functionality doesn't rely
on having a DOM around...

Cheers,

Simon


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