From: Wolfgang M. <me...@if...> - 2003-04-11 08:29:46
|
Hi, actually, you don't have to use the XPathAPI for the post-processing. eXi= st=20 supports nested queries, i.e. you can execute a second query on the resou= rce=20 you retrieved from a first query. To use this feature, you have to cast y= our=20 XPathService to org.exist.xmldb.XPathServiceImpl. Then you can do: while(results.hasMoreResources()) { =09... =09XMLResource resource =3D (XMLResource)results.nextResource(); =09... =09ResultSet rs =3D ((org.exist.xmldb.XPathQueryService)service).query(re= source,=20 "/canal/canal_name"); =09c.setResource((String)rs.getResource(0L).getContent()); } This should be much safer than using xalan for the post-processing. I'm n= ot=20 sure if eXist's DOM is fully compatible with xalan (though I know it work= s=20 with Jaxen). Regards, Wolfgang On Friday 11 April 2003 01:16 am, Matthew Furister wrote: > I am currently using eXist9.1 and am pretty new to the program. I have > embedded it into a java application that I am writing and am trying to = use > XPathAPI to get the values of the element. > > What I want is the value only. The problem is that XPathAPI.eval(node, > string) seems to hang. It does not throw an exception, yet it will not = move > on from this call. > > When I print out the node, everything seems to be ok. > > I am on a severe time crunch, so any immediate ideas will be extremly > helpful. If anyone has ANY ideas, please post them immediatly. > > Thanks for your help.... > > -- Matt > > Example: > =09<canal> > =09=09<canal_name>Canal1</canal_name> > =09=09<canal_resource>canal_1</canal_resource> > =09</canal> > > > > The Code: > //<imports> > import java.util.Vector; > import java.util.Hashtable; > import org.xmldb.api.base.*; > import org.xmldb.api.modules.*; > > import org.w3c.dom.*; > > import org.apache.xpath.*; > import org.apache.xpath.objects.*; > > //<method> > public void addResults(ResourceIterator results) { > System.out.println("ADDING RESULTS"); > try { > System.out.println("TRYING"); > while (results.hasMoreResources()) { > System.out.println("WHILE..."); > // Create a new canal instance to add to Group > Canal c =3D new Canal(); > > // Retrieve the next node > XMLResource resource =3D (XMLResource) results.nextResource= (); > > // Cast to Dom Node > > Node originalnode =3D resource.getContentAsDOM(); > System.out.println(originalnode.toString()); > > // Get the document key for this node for later use > String dockey =3D resource.getDocumentId(); > c.setDocKey(dockey); > > // Use Xalan xpath parser to extract data, store into hasta= ble > XObject xo =3D new XObject(); > XPathAPI xp =3D new XPathAPI(); > xo =3D xp.eval(originalnode, "/canal/canal_name"); > System.out.println(xo.toString()); > c.setName(xo.toString()); > > xo =3D XPathAPI.eval(originalnode, "/canal/canal_resource")= ; > c.setResource(xo.toString()); > > // Add person to group > this.add(c); > } > } > catch (Exception e) { > e.printStackTrace(); > } > System.out.println("OUT OF WHILE"); > } > > > ------------------------------------------------------- > This SF.net email is sponsored by: Etnus, makers of TotalView, The debu= gger > for complex code. Debugging C/C++ programs can leave you feeling lost a= nd > disoriented. TotalView can help you find your way. Available on major U= NIX > and Linux platforms. Try it free. www.etnus.com > _______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open --=20 Wolfgang Meier Darmstadt University of Technology TELOS Working Group, Dept. of Soc. Residenzschlo=DF D-64283 Darmstadt, Germany +49 (0)6151-163215 mailto:me...@if... http://www.sozionet.org =20 |