-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-xml-data-functions.linq
82 lines (65 loc) · 3.21 KB
/
parse-xml-data-functions.linq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<Query Kind="Statements">
<Reference><RuntimeDirectory>\System.Web.dll</Reference>
<Reference><RuntimeDirectory>\System.Configuration.dll</Reference>
<Reference><RuntimeDirectory>\System.DirectoryServices.dll</Reference>
<Reference><RuntimeDirectory>\System.EnterpriseServices.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.RegularExpressions.dll</Reference>
<Reference><RuntimeDirectory>\System.Design.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.ApplicationServices.dll</Reference>
<Reference><RuntimeDirectory>\System.ComponentModel.DataAnnotations.dll</Reference>
<Reference><RuntimeDirectory>\System.DirectoryServices.Protocols.dll</Reference>
<Reference><RuntimeDirectory>\System.Security.dll</Reference>
<Reference><RuntimeDirectory>\System.Runtime.Caching.dll</Reference>
<Reference><RuntimeDirectory>\System.ServiceProcess.dll</Reference>
<Reference><RuntimeDirectory>\System.Web.Services.dll</Reference>
<Reference><RuntimeDirectory>\Microsoft.Build.Utilities.v4.0.dll</Reference>
<Reference><RuntimeDirectory>\Microsoft.Build.Framework.dll</Reference>
<Reference><RuntimeDirectory>\Microsoft.Build.Tasks.v4.0.dll</Reference>
<Reference><RuntimeDirectory>\System.Windows.Forms.dll</Reference>
</Query>
var xmlPath = @"C:\Users\James\Projects\Standalone\LogParserPlus\LogParserPlus.Web\App_Data\functions.xml";
var mdPath = @"C:\Users\James\Projects\logparserplus.com\content\functions\";
var xmlItems = XDocument.Load(xmlPath).Descendants("function");
var filePath = "";
foreach (var xmlItem in xmlItems)
{
filePath = mdPath + xmlItem.Element("name").Value.ToLower() + ".md";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
var fileData = new StringBuilder();
fileData.AppendLine("+++");
fileData.AppendFormat("name = \"{0}\"" + Environment.NewLine, xmlItem.Element("name").Value);
var syntaxRaw = System.Web.HttpUtility.HtmlDecode(xmlItem.Element("syntax").Value);
fileData.AppendFormat("syntax = \"{0}\"" + Environment.NewLine, syntaxRaw);
fileData.AppendFormat("description = \"{0}\"" + Environment.NewLine, xmlItem.Element("description").Value);
fileData.AppendFormat("type = \"{0}\"" + Environment.NewLine, xmlItem.Element("type").Value);
// Related.
var relatedItems = xmlItem.Elements("related").Select(e => e.Value).Where(e => !string.IsNullOrWhiteSpace(e));
if (relatedItems.Any())
{
fileData.AppendFormat("related = [\"{0}\"]" + Environment.NewLine, string.Join("\", \"", relatedItems));
}
//fileData.AppendFormat(" = \"{0}\"" + Environment.NewLine, xmlItem.Element("").Value);
fileData.AppendLine("+++");
fileData.AppendLine("");
var examples = xmlItem.Element("examples").Descendants().Where(e => !string.IsNullOrWhiteSpace(e.Value));
if (examples.Any())
{
examples.Dump();
fileData.AppendLine("#### Examples");
foreach (var example in examples)
{
fileData.AppendFormat("- {0}{1}"
, example.Value
.Replace("<span>", "`")
.Replace("</span>", "` " + Environment.NewLine + " ")
, Environment.NewLine);
}
}
// Examples.
fileData.ToString().Dump();
File.WriteAllText(filePath, fileData.ToString());
}
xmlItems.Dump();