If we have this xml file and I want to use the attribute Author as a variable to get the title
<bookstore>
<book author="Tommy">
<title>Emma</title>
</book>
</bookstore>
I know that I must write this
string au = "Tommy";
string query = String.Format("//bookstore/book[@author={0}]/title", au);
If we also have this example and I want to get the title
<bk:bookstore xmlns:bk="http://www.example.com/">
<book author="Tommy">
<title>Emma</title>
</book>
</bk:bookstore>
I know that I must write this
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("bk", "http://www.test.com/");
XmlNodeList elements0 = xml.SelectNodes("//bk:bookstore/book/title", nsmgr);
But I don't know what to do if I have the second example and I also want to use the attribute Author as a variable. I have tried this
string au = "Tommy";
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
nsmgr.AddNamespace("bk", "http://www.test.com/");
XmlNodeList elements0 = xml.SelectNodes("//bk:bookstore/book[@author={0}]/title", au, nsmgr);
or this
XmlNodeList elements0 = xml.SelectNodes("//bk:bookstore/book[@author={0}]/title", nsmgr, au);
or this
XmlNodeList elements0 = xml.SelectNodes("//bk:bookstore/book[@author={1}]/title", nsmgr, au);
but it doesn't work. Could anybody help me?