• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java XPath on multiple files

 
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Suppose we have two separate XML files. One is a File of books. The other is a file of authors.
Is it possible to write an XPath expression which will query both files at the same time and perform a join of the two?

An analogy would be. Each file corresponds to a SQL table. Now it would be easy to write a SQL join query across the two tables. How about Xpath?

Any tips appreciated.

Thanks.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A single XPath expression is only going to operate on one DOM at a time.

The objects returned by evaluating a single XPath expression will be in the context of that DOM.

It will be up to you, the programmer, to figure out how to combine multiple results.

Bill
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The situation can be summaried somewhat like this.

In the technologies proposed within the w3c's charter, to query an "external" document(s) at the time of having a specific context of a loaded xml document, there disposes a document() function in xslt 1.0 and continued to carry along to xslt 2.0. But, it should only be recognized by the xslt engine. In the xpath 1.0, there isn't any window opened to query the external document(s) at the same time of it (the xpath engine) having a context. But, in xpath 2.0, there is now an xpath function proper (not necessarily being used in xslt) disposed for the purpose, namely, the built-in doc(). And then, the xquery recommendation, worked out in close collaboration with the group for xslt 2.0 is the closest in the spirit to what the sql is for relational db. In xquery, it should gurantee on xpath 2.0 support right at the beginning. And there is a built-in doc() for the purpose as well.
 
Luke Murphy
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

g tsuji wrote:The situation can be summaried somewhat like this.

In the technologies proposed within the w3c's charter, to query an "external" document(s) at the time of having a specific context of a loaded xml document, there disposes a document() function in xslt 1.0 and continued to carry along to xslt 2.0. But, it should only be recognized by the xslt engine. In the xpath 1.0, there isn't any window opened to query the external document(s) at the same time of it (the xpath engine) having a context. But, in xpath 2.0, there is now an xpath function proper (not necessarily being used in xslt) disposed for the purpose, namely, the built-in doc(). And then, the xquery recommendation, worked out in close collaboration with the group for xslt 2.0 is the closest in the spirit to what the sql is for relational db. In xquery, it should gurantee on xpath 2.0 support right at the beginning. And there is a built-in doc() for the purpose as well.



Thanks for this. So what's the corresponding Java API (if any?)?
 
g tsuji
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is sometimes not the apparent api (name of the methods or even the signatures) that differentiate xpath 1.0 support vs xpath 2.0 support. It is the implementation, class library that makes clear the different level of supports. It can be. But since jaxp xpath package (java 5) provides a somewhat object-model independent library, implementers can make implementation of it and expose methods with same signature so that people can write code and transit more smoothly from one version to the next. Of course, they can have their own specific api's, that their own right.

The most noticeable implementations are like Saxon that you can trace to its documentation. This is a lead (not the documentation to its latest release itself), dated and contained trial typo.
http://saxon.sourceforge.net/saxon7.5/api-guide.html
Or, how about Oracle xdk 11g?
http://download.oracle.com/docs/cd/E12839_01/appdev.1111/b28394/adx_ref_standards.htm
and no doubt others commercial or free in different stage of development or completion that it suffices a googling to discover.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic