Created
June 12, 2014 02:27
-
-
Save cilerler/c37bbea3e56a5ffdd5c4 to your computer and use it in GitHub Desktop.
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
private IEnumerable<string> GetElementNames(XElement xElement, string path) | |
{ | |
var output = new List<string>(); | |
if (string.IsNullOrWhiteSpace(path)) | |
{ | |
path = xElement.Name.ToString(); | |
output.Add(path); | |
if (xElement.HasAttributes) | |
{ | |
output.AddRange(GetAttributesName(xElement, path)); | |
} | |
} | |
foreach (XElement element in xElement.Elements()) | |
{ | |
string name = element.Name.ToString(); | |
string fullName = path + "/" + name; | |
output.Add(fullName); | |
if (element.HasAttributes) | |
{ | |
output.AddRange(GetAttributesName(element, path)); | |
} | |
if (!element.HasElements) | |
{ | |
continue; | |
} | |
output.AddRange(GetElementNames(element, fullName)); | |
} | |
return output.OrderBy(o => o); | |
} | |
private IEnumerable<string> GetAttributesName(XElement xElement, string path) | |
{ | |
IEnumerable<string> output = xElement.Attributes() | |
.Select(e => string.Format("{0}/{1}", path, e.Name.ToString())); | |
return output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment