Created
November 13, 2013 19:55
-
-
Save douglas-mason/7455307 to your computer and use it in GitHub Desktop.
Grabs value of specified attribute from a site map node. If recursive search is specified, then search up the site map tree for the next ancestor node that contains a value for the specified attribute.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetNodeAttributeValue(SiteMapNode currentNode, string attributeName, bool recursive) | |
{ | |
if (recursive) // Do recursive search | |
{ | |
string attributeValue = ""; | |
if (currentNode != null) | |
{ | |
attributeValue = GetNodeAttributeValue(currentNode, attributeName, false); // Search node currently working with. | |
if (string.IsNullOrEmpty(attributeValue)) // If attribute not found, then check the parent node. | |
{ | |
if (currentNode.ParentNode != null) | |
{ | |
attributeValue = GetNodeAttributeValue(currentNode.ParentNode, attributeName, true); | |
} | |
} | |
} | |
return attributeValue; | |
} | |
else // Search currentNode only | |
{ | |
if (currentNode != null && currentNode[attributeName] != null) | |
{ | |
return currentNode[attributeName]; | |
} | |
else | |
{ | |
return ""; // If attribute is not found return empty string. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment