private static bool HandleInclude (MemberCore mc, XmlElement el, Report Report)
{
bool keep_include_node = false;
string file = el.GetAttribute ("file");
string path = el.GetAttribute ("path");
if (file == "") {
Report.Warning (1590, 1, mc.Location, "Invalid XML `include' element. Missing `file' attribute");
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" Include tag is invalid "), el);
keep_include_node = true;
}
else if (path.Length == 0) {
Report.Warning (1590, 1, mc.Location, "Invalid XML `include' element. Missing `path' attribute");
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" Include tag is invalid "), el);
keep_include_node = true;
}
else {
XmlDocument doc;
if (!RootContext.Documentation.StoredDocuments.TryGetValue (file, out doc)) {
try {
doc = new XmlDocument ();
doc.Load (file);
RootContext.Documentation.StoredDocuments.Add (file, doc);
} catch (Exception) {
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (String.Format (" Badly formed XML in at comment file `{0}': cannot be included ", file)), el);
Report.Warning (1592, 1, mc.Location, "Badly formed XML in included comments file -- `{0}'", file);
}
}
if (doc != null) {
try {
XmlNodeList nl = doc.SelectNodes (path);
if (nl.Count == 0) {
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" No matching elements were found for the include tag embedded here. "), el);
keep_include_node = true;
}
foreach (XmlNode n in nl)
el.ParentNode.InsertBefore (el.OwnerDocument.ImportNode (n, true), el);
} catch (Exception ex) {
el.ParentNode.InsertBefore (el.OwnerDocument.CreateComment (" Failed to insert some or all of included XML "), el);
Report.Warning (1589, 1, mc.Location, "Unable to include XML fragment `{0}' of file `{1}' ({2})", path, file, ex.Message);
}
}
}
return keep_include_node;
}