Hello,

Here is the sample code:

src/test/Main.java :
package test;

import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.xml.DocumentContainer;
import org.w3c.dom.Element;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class Main {
   public static void main(String[] args) throws IOException {
       JXPathContext context = JXPathContext.newContext(
               new DocumentContainer(new File("test.xml").toURI().toURL())
       );
       List abcs = context.selectNodes("//abc");
       for (Object o : abcs) {
           Element el = (Element) o;
           System.out.printf("1: %s a=%s%n", el.getNodeName(),
el.getAttribute("a"));
       }
       JXPathContext subcontext = JXPathContext.newContext(abcs);
       List detailedAbcs = subcontext.selectNodes("*");
       for (Object o : detailedAbcs) {
           Element el = (Element) o;
           System.out.printf("2: %s a=%s%n", el.getNodeName(),
el.getAttribute("a"));
       }
   }
}

test.xml:
<root>
   <abc a="1"/>
   <abc a="2"/>
   <abc a="3"/>
</root>

Result:
1: abc a=1
1: abc a=2
1: abc a=3

The second query "*" resulted in empty sequence. If I query for "/"
instead of "*", I get the three abc elements, but for "/*" result is
empty again. So... how do you think I could get all abc elements where
a=1 from subcontext ?

Thanks,
Yuri.

2007/5/24, Matt Benson <[EMAIL PROTECTED]>:
At first glance it appears this, or something similar,
should be sufficient for what you want to do.  Please
assemble some sample code and explain where it is
failing.

Thanks,
Matt

--- Yuri Ushakov <[EMAIL PROTECTED]> wrote:

> Hello.
>
> I can't find a way, yet I think it should be
> possible to do something like this:
>
> JXPathContext subcontext =
>
JXPathContext.newContext(context.selectNodes("//abc"));
>
> So then subcontext would point to a new sequence and
> I could do
> selects on abc elements in it. When I try to do as
> above, I'm simply
> "browsing" a List implementation object... But I
> need to be able to
> execute a query like this:
>
> subcontext.selectNodes("[EMAIL PROTECTED](@b)]");
>
> Where "*" is abc elements selected from first query.
> Any tips?
>
> Thanks,
> Yuri.
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
>




____________________________________________________________________________________Pinpoint
 customers who are looking for what you sell.
http://searchmarketing.yahoo.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to