开发者

What do "+", "@" and "*" mean in an XPath query?

开发者 https://www.devze.com 2022-12-24 08:29 出处:网络
On the iReport documentation I found these XPath queries: /addressbook/category@name /addressbook/category/person@id

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/@nam开发者_C百科e?
  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>email1@my.domain.it</email>
      <email>email2@my.domain2.it</email> 
     ...

(Full XML here)


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号