You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ahmed Elshereay <AE...@idc.com> on 2010/07/16 12:46:48 UTC

xpath query problem

Hi All,

Can anyone please tell me what is wrong in this statment?

          String statement = "//element(*, 
nt:unstructured)[jcr:like(@jcr:name, 'event%')] order by @jcr:name 
descending";

        Query q = 
session.getWorkspace().getQueryManager().createQuery(statement, 
Query.XPATH);
        NodeIterator nodes = q.execute().getNodes();

There are a lot of nodes with name starts with 'event', also I tried to 
use [@jcr:name='history'] as I have nodes that have exact name 'history', 
but always the itereator is empty!

Notice, when the statement is like:  "//element(*, nt:unstructured)" 
without constraints then it works and return results.

So can anyone please help me what could be the problem?
I use jackrabbit 2.1.0, I know xpath is depricated, but I have to use the 
xpath.

Thank you in advance.

Re: xpath query problem

Posted by Ard Schrijvers <a....@onehippo.com>.
On Fri, Jul 16, 2010 at 4:08 PM, Ahmed Elshereay <AE...@idc.com> wrote:
> Hi Ard,
>
> Your suggestion is even easier, Thank you very much :-)

I thought so as well...I needed it in the past as well so did know
where to find it :-)

You're welcome,

Regards Ard

>
> Ahmed

Re: xpath query problem

Posted by Ahmed Elshereay <AE...@idc.com>.
Yes, I used the first suggestion.

Thank you very much :-)

Re: xpath query problem

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jul 16, 2010 at 14:26, Ard Schrijvers <a....@onehippo.com> wrote:
> org.apache.jackrabbit.value.ValueFactoryImpl.getInstance().createValue(value).getString()

Shouldn't that be session.getValueFactory().createValue(calendar).getString() ?

Alternatively you can use ISO8601.format(calendar) from the
jackrabbit-jcr-commons library.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: xpath query problem

Posted by Ahmed Elshereay <AE...@idc.com>.
Hi Ard,

Your suggestion is even easier, Thank you very much :-)

Ahmed

Re: xpath query problem

Posted by Ard Schrijvers <a....@onehippo.com>.
Hello Ahmed,

you can also use it like it is used in jackrabbit:

Calendar value = ... ;

"xs:dateTime('"+org.apache.jackrabbit.value.ValueFactoryImpl.getInstance().createValue(value).getString()
+ "')";

Regards Ard

On Fri, Jul 16, 2010 at 2:17 PM, Ahmed Elshereay <AE...@idc.com> wrote:
> Hi,
>
> I found how to get an XML date format in java, here's the way:
>
> GregorianCalendar cal = new GregorianCalendar(2010, Calendar.JULY, 15, 15,
> 29, 17);
> XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance
> ().newXMLGregorianCalendar(cal);
>
> Then...
>
> xs:dateTime('" + xmlCal.toXMLFormat() + "')
>
>  Thank you Alex.

Re: xpath query problem

Posted by Ahmed Elshereay <AE...@idc.com>.
Hi,

I found how to get an XML date format in java, here's the way:

GregorianCalendar cal = new GregorianCalendar(2010, Calendar.JULY, 15, 15, 
29, 17);
XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance
().newXMLGregorianCalendar(cal);

Then...

xs:dateTime('" + xmlCal.toXMLFormat() + "')

 Thank you Alex.

Re: xpath query problem

Posted by Ahmed Elshereay <AE...@idc.com>.
Hi Alex,

Thank you too much for your help, now it works :-)

But please I have another question, I also want to search for event nodes 
that have the jcr:created property < or > some Date, and I know I can use 
xs:dateTime() to say for example:
[fn:name() = 'event' and @jcr:created >= 
xs:dateTime('2010-07-15T01:29:50.050Z')]

I tried to pass the xs:dateTime() a someJavaDate.toString() but it didn't 
work!

How can I get the xs:dateTime() parameter value from a java Date?

Thank you once more for your help.

Re: xpath query problem

Posted by Alexander Klimetschek <ak...@day.com>.
On Fri, Jul 16, 2010 at 12:46, Ahmed Elshereay <AE...@idc.com> wrote:
> Can anyone please tell me what is wrong in this statment?
>
>          String statement = "//element(*,
> nt:unstructured)[jcr:like(@jcr:name, 'event%')] order by @jcr:name
> descending";
>
>        Query q =
> session.getWorkspace().getQueryManager().createQuery(statement,
> Query.XPATH);
>        NodeIterator nodes = q.execute().getNodes();
>
> There are a lot of nodes with name starts with 'event', also I tried to
> use [@jcr:name='history'] as I have nodes that have exact name 'history',
> but always the itereator is empty!

There is no "jcr:name" (pseudo)-property. For an exact node name
match, you can use fn:name() = 'event'. Wild card matches such as
jcr:like() are not possible on node names with XPath or SQL from JCR
1.0. You can use JCR-SQL2 in JCR 2.0 for that. See
http://jackrabbit.markmail.org/thread/xvoo5afksxtyplhw

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com