Find XmlNode where attribute value is contained in string

Posted by bflemi3 on Stack Overflow See other posts from Stack Overflow or by bflemi3
Published on 2012-06-29T14:20:51Z Indexed on 2012/06/29 21:16 UTC
Read the original article Hit count: 178

Filed under:
|
|
|

I have an xml file...

<?xml version="1.0" encoding="UTF-8"?>
<items defaultNode="1">
    <default contentPlaceholderName="pageContent" template="" genericContentItemName="" />
    <item urlSearchPattern="connections-learning" contentPlaceholderName="pageContent" template="Connections Learning Content Page" genericContentItemName="" />
    <item urlSearchPattern="online-high-school" contentPlaceholderName="pageContent" template="" genericContentItemName="" />
</items>

I am trying to find the first node where the urlSearchPattern attribute is contained in the string urlSearchPattern. Where I'm having trouble is finding the nodes where the attribute is contained in the string value instead of the string value be contained in the attribute.

Here's my attempt so far. This will find the firstOrDefault node where the string value is contained in the attribute (I need the opposite)...

string urlSearchPattern = Request.QueryString["aspxerrorpath"];
MissingPageSettingsXmlDocument missingPageSettingsXmlDocument = new MissingPageSettingsXmlDocument();
XmlNode missingPageItem = missingPageSettingsXmlDocument.SelectNodes(ITEM_XML_PATH).Cast<XmlNode>().Where(item => item.Attributes["urlSearchPattern"].ToString().ToLower().Contains(urlSearchPattern)).FirstOrDefault();

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml