tags:

views:

68

answers:

1

On the iReport documentation I found these XPath queries:

/addressbook/category@name
/addressbook/category/person@id
/addressbook/category/person+LASTNAME
/addressbook/category/person+FIRSTNAME
/addressbook/category/person+hobbies*hobby

My questions:

  1. Is category@name the same as category/@name?
  2. What's the meaning of person+LASTNAME? (The + to be precise)
  3. What's the meaning of person+hobbies*hobby (The * to be precise)

They are applied to this XML:

<addressbook>
 <category name="home">
    <person id="1">                                                           
      <LASTNAME>Davolio</LASTNAME>
      <FIRSTNAME>Nancy</FIRSTNAME>
      <hobbies>
        <hobby>Radio Control</hobby>
        <hobby>R/C Cars</hobby>
        <hobby>Micro R/C Cars</hobby>
        <hobby>Die-Cast Models</hobby>
      </hobbies>
      <email>[email protected]</email>
      <email>[email protected]</email> 
     ...

(Full XML here)

+3  A: 

That's not XPath. It's just XPath-like. From the page that you linked:

<symbol> is used to add an extra path to the base path and to define what should be returned.
+ add the following path to the base_path (this happen when the base_path = record path);
@ return the attribute value: it's followed by the attribute name;
* return all tags identified by the following path as a JRXMLDatasource

It's in section 7.3 of the link you have in your question.

So, going from that, these are the meanings of your XPath-like expressions:

/addressbook/category@name
  The basepath is /addressbook/category, return the attribute "name"

/addressbook/category/person@id
  The basepath is /addressbook/category/person, return the attribute "id"

/addressbook/category/person+LASTNAME
  The basepath is /addressbook/category/person, return the element "LASTNAME"

/addressbook/category/person+FIRSTNAME
  The basepath is /addressbook/category/person, return the element "FIRSTNAME"

/addressbook/category/person+hobbies*hobby
  The basepath is /addressbook/category/person, look inside "hobbies"
  and return all elements named "hobby"
Welbog
I also found this and wondered why they re-invent the wheel. All this functionality is available in XPath.
0xA3
@divo: Agreed. This doesn't make any sense. XPath can do everything that these expressions seem to be indicating.
Welbog
Well, it's a little shorter; xpath doesn't make the distinction between base and relative like this - you'd need two columns i.e. base:`/addressbook/category/person` selects:`hobbies/hobby` - which doesn't explain why they reinvent the wheel, but it's not replacable with a *single* xpath, anyhow...
Eamon Nerbonne
I have overlooked it, how embarrassing :) But thanks for your examples, they make understanding easier.
DR