简体   繁体   中英

Get Value from XML File based on two child node values

I have an xml document and need XPath expression to select node values based on two child node values. XML File structure is:

<catalog>
<book id="123"> 
<title>Book123</title>
<author>Author123</author>
<genre>Genre123</genre>
</book>
.
.
.
</catalog>

I want to select book based on title and author. I've used this expression but it shows an exception which said this expression has some invalid token. I didn't figure it out how to solve this. Expression is :

"book[title='" + txtBookTitle.Text + "' AND author='" + txtBookAuthor.Text + "']"

Any body help me in this regard ?

你可以用

//book[title[text()='Book123'] and author[text()='Author123']]

Try

//book[title='Book123' and author='Author123']

as your XPath. It might be worth checking you've trimmed the spaces on your inputs using .Trim(), eg

TextBox1.Text.Trim()

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