|
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
using System.Text;
using System;
namespace Rob.Utils
{
public static class XmlUtils
{
#region Public Methods
public static string readAttribute(XElement element, string attribute)
{
return readAttribute<string>(element, attribute, val => val);
}
public static T readAttribute<T>(XElement element, string attribute, Func<string, T> translator)
{
return readAttribute<T>(element, attribute, default(T), translator);
}
public static T readAttribute<T>(XElement element, string attribute, T defaultValue, Func<string, T> translator)
{
if (element.Attribute(attribute) != null)
return translator(element.Attribute(attribute).Value);
else
return defaultValue;
}
public static IEnumerable<XElement> readChildren(XElement element, XName childName)
{
foreach (XElement child in element.Elements().Where(child => child.Name.Equals(childName)))
yield return child;
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.