“+”,“@”和“*”在XPath查询中的含义是什么?

时间:2010-03-25 17:55:48

标签: xpath

在iReport文档中,我发现了这些XPath查询:

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

我的问题:

  1. category@namecategory/@name相同吗?
  2. person+LASTNAME的含义是什么? (确切地说 +
  3. person+hobbies*hobby的含义是什么(确切地说 *
  4. 它们适用于此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> 
         ...
    

    (完整XML here

1 个答案:

答案 0 :(得分:3)

那不是XPath。它就像XPath一样。从您链接的页面:

  

<symbol>用于向基本路径添加额外路径并定义应返回的内容   +将以下路径添加到base_path(这在base_path =记录路径时发生);
  @返回属性值:后跟属性名称;
  *将以下路径标识的所有标记返回为JRXMLDatasource

它在section 7.3 of the link you have in your question

所以,从那里开始,这些就是你的类XPath表达式的含义:

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