C# XML - XPath Query Builder - Dynamically Create a Query
<p>I am trying to build a XPath Query Builder in order to have a generic code as portable as possible.</p>

<p>So far, this is what I came up with :</p>

<pre><code>private static string XpathQueryBuilder (string NodeName,string AttributeName = null, string AttributeValue = null)
    {

        string XpathAttr = "";

        if (AttributeName != null)
            if (AttributeValue != null)
                XpathAttr = "[@" + AttributeName + "='" + AttributeValue + "']";
            else
                XpathAttr = "[@" + AttributeName + "='*']";
        return "//" + NodeName + XpathAttr;

    }    
</code></pre>

<p>The problem I see with this method though is that if I have more than one attribute or node that I would like to look for, this function won't work. Is there a way to create an XPath Query dynamically that could theorically accept any number of attributes and/or Nodes.</p>

<p>My priority is on having a function that accepts more than one attribute and attribute value as this is the more likely case than more than one node.</p>

<p>Thank you for your time!</p>