Thanks for the assistance guys (or girls) :)
THe issue was the XmlDocument.Load function; I was trying to point to an xml
file located in another project; .NET did not return an error but NOR did it
return any XML, which is why I created this post. I placed the XML file
locally, and made its path the argument in the xmldocument.load() method. It
does indeed accept c# variables in the Xpath statement!
"Brian Brown" wrote:
Hi,
From the code sample that you provided I cannot get the code to reproduce
the behavior that you are describing. I have created a sample app that
attempts to mimic your code. You should be able to create a console
application and then cut and paste the code below. Don’t forget to adjust
the path to the xml document.
I hope that this helps!
-----------------------------Sample Console App (watch for line wrap)
using System;
using System.Xml;
using System.Xml.XPath;
namespace ConsoleTestApp
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string csharpvariablename = "story";
XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"C:\books.xml");
XmlNodeList nodeList;
XmlElement root = xdoc.DocumentElement;
nodeList =
xdoc.SelectNodes("/bookstore/book[@genre=\""+ csharpvariablename +"\"]");
foreach(XmlNode n in nodeList)
Console.WriteLine(n.InnerText.ToString());
}
}
}
----------------------------- XML Document - Books.xml
<?xml version="1.0"?>
<!-- A fragment of a book store inventory database -->
<bookstore >
<book genre="story" publicationdate="1997">
<title>Pride And Prejudice</title>
<author>
<first-name>Jane</first-name>
<last-name>Austen</last-name>
</author>
<price>24.95</price>
</book>
<book genre="novel" publicationdate="1992">
<title>The Handmaid's Tale</title>
<author>
<first-name>Margaret</first-name>
<last-name>Atwood</last-name>
</author>
<price>29.95</price>
</book>
<book genre="story" publicationdate="1991">
<title>Emma</title>
<author>
<last-name>Austen</last-name>
</author>
<price>19.95</price>
</book>
<book genre="novel" publicationdate="1982">
<title>Sense and Sensibility</title>
<author>
<first-name>Jane</first-name>
</author>
<price>19.95</price>
</book>
</bookstore>