Linq XML XInclude:
public static class XIncludeExtention
{
#region fields
public static readonly XNamespace IncludeNamespace = "http://www.w3.org/2003/XInclude";
public static readonly XName IncludeElementName = IncludeNamespace + "include";
public const string IncludeLocationAttributeName = "href";
public const int MaxSubIncludeCountDefault = 25;
#endregion
#region methods
public static void ReplaceXIncludes(this XDocument xDoc, int maxSubIncludeCount = MaxSubIncludeCountDefault)
{
ReplaceXIncludes(xDoc.Root, maxSubIncludeCount);
}
public static void ReplaceXIncludes(this XElement xmlElement, int maxSubIncludeCount = MaxSubIncludeCountDefault)
{
xmlElement.ReplaceXIncludes(1, maxSubIncludeCount);
}
private static void ReplaceXIncludes(this XElement xmlElement, int subIncludeCount, int maxSubIncludeCount)
{
var results = xmlElement.DescendantsAndSelf(IncludeElementName).ToArray<XElement>();
foreach (var includeElement in results)
{
var path = includeElement.Attribute(IncludeLocationAttributeName).Value;
path = Path.GetFullPath(path);
var doc = XDocument.Load(path);
if (subIncludeCount <= maxSubIncludeCount)
{
doc.Root.ReplaceXIncludes(++subIncludeCount, maxSubIncludeCount);
}
includeElement.ReplaceWith(doc.Root);
}
}
#endregion
}
: http://catarsa.com/Articles/Blog/Any/Any/Linq-To-Xml-XInclude?MP=pv
XInclude: http://msdn.microsoft.com/en-us/library/aa302291.aspx