开发者

How to retrieve XML data using XPath Expression

开发者 https://www.devze.com 2023-01-20 09:07 出处:网络
I have a XMLDataSource som开发者_Go百科ewhat like: <bookstore> <author>author1</author>

I have a XMLDataSource som开发者_Go百科ewhat like:

<bookstore>
  <author>author1</author>
  <publication>publication1</publication>
  <book>
    <genre>Thriller</genre>
    <name>ABC</name>
  </book>
  <book>
    <genre>Romance</genre>
    <name>XYZ</name>
  </book>
  <book>
    <genre>Horror</genre>
    <name>000</name>
  </book>
</bookstore>

I am storing these in a asp:formview. I am able to store author and publication values but not sure how can I store the value of book/name based on some condition? Actually I just want to use condition that I need to store the value of "name" if "genere=Romance". something like this. I tried using XPath expression bookstore/book/genre[. ='Romance'] but not sure how to access the value of tag. Checked the following resource:

http://msdn.microsoft.com/en-us/library/ms256086.aspx

Appreciate if someone can help me.


I tried using XPath expression bookstore/book/genre[. ='Romance'] but not sure how to access the value of tag

Almost. This XPath expression:

/bookstore/book[genre='Romance']/name

String value: XYZ


You probably need to add /text() to get the contents of the XML tag instead of just the tag. There is a great XML cheat-sheet here that should help you.

0

精彩评论

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