开发者

How to retrieve XML data using XPath Expression

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜