简体   繁体   中英

Getting incorrect result with XQuery?

Below is the XMl File -

<Chapters>
  <Chapter n="1">
    <Desc>....</Desc>
    <References>
       <BookRef>HTML : in 21 Days</BookRef>
       <Page>12, 13</Page>
       <BookRef>HTML : Unlimited</BookRef>
       <Page>21, 22</Page>
       <BookRef>The Complete Reference - HTML</BookRef>
       <Page>32-35</Page>
    </References>
  </Chapter>
  <Chapter n="2">
    <Desc>....</Desc>
    <References>
       <BookRef>HTML : in 21 Days</BookRef>
       <Page>52, 53</Page>
       <BookRef>The Complete Reference - HTML</BookRef>
       <Page>132-145</Page>
       <BookRef>The Complete Reference - Javascript</BookRef>
       <Page>132-145</Page>
    </References>
  </Chapter>
</Chapters> 

I am trying to list - all the containing HTML word using /Chapters/Chapter/References[BookRef contains text 'HTML']/BookRef

But all are being displayed...!! What will be the XQuery to retrieve the same?

Try the following one:

/Chapters/Chapter/References/BookRef[. contains text 'HTML']

Otherwise, all References nodes will be returned that have a BookRef node containing HTML , and the following step will return all BookRef nodes (ie, you lose the information which of the BookRef nodes had the searched token).

您要

/Chapters/Chapter/References/BookRef[contains(., 'HTML')]

使用XPath = /Chapters/Chapter/References/BookRef[contains(., 'HTML')]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM