sakis297 0 Newbie Poster

Hello!!!
If I have this

<bookstore>
   <book author="Tommy">
     <title>Emma</title>
   </book>
</bookstore>

and I want to get the node, I know that I must write this.

 string au = "Tommy";
 string query = String.Format("//bookstore/book[@author={0}]/title", au);

Also, if I have this

<bk:bookstore xmlns:bk="http://www.test.com/">
   <book author="Tommy">
     <title>Emma</title>
   </book>
</bk:bookstore>

and I want to get the node, 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 case and I want to use the attribute author as avariable.
I try this but it doesn't work.

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

XmlNodeList elements0 = xml.SelectNodes("//bk:bookstore/book[@author={0}]/title", nsmgr, au); 

What should I do?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.