开发者

Parsing Xml via XPath gives error

I have a very simple xml string that I loaded using XmlDocument class. Now I am trying to read it via XPath query and I get this error,

"Expression must evaluate to a node-set."

Here is my Xml,

<RF_SearchTermBanners>
   <ImageName>3pc-leather-set.jpg</ImageName>
</RF_SearchTermBann开发者_如何学Goers>

Here is my C# code,

protected void BindSearchBanner(string ImageUrl)
{
    //Parse Xml string containing Image name
    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
    xmlDoc.LoadXml(ImageUrl);

    System.Xml.XmlNode node = (System.Xml.XmlNode)xmlDoc.DocumentElement;
    System.Xml.XmlElement imageElem = node.SelectSingleNode("@/RF_SearchTermBanners/ImageName") as System.Xml.XmlElement;

    string imgUrl = imageElem.InnerText;

    if (imgUrl != null && imgUrl != string.Empty)
    {
        SearchBanner.ImageUrl = "~/Themes/Default/Images" + imgUrl;
        SearchBanner.Visible = true;
    }
    else
    {
        SearchBanner.ImageUrl = string.Empty;
        SearchBanner.Visible = false;
    }
}

Please help.


Did you mean @"/RF_SearchTermBanners/ImageName"? In XPath, an @ symbol represents an attribute.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜