-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse-xml-data-examples.linq
138 lines (118 loc) · 5.84 KB
/
parse-xml-data-examples.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<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\queries.xml";
var mdPath = @"C:\Users\James\Projects\logparserplus.com\content\examples\";
var xmlItems = XDocument.Load(xmlPath).Descendants("query");
var filePath = "";
foreach (var xmlItem in xmlItems)
{
xmlItem.Dump();
filePath = mdPath + xmlItem.Attribute("id").Value + ".md";
if (File.Exists(filePath))
{
File.Delete(filePath);
}
var fileData = new StringBuilder();
fileData.AppendLine("+++");
fileData.AppendFormat("id = {0}" + Environment.NewLine, xmlItem.Attribute("id").Value);
fileData.AppendFormat("name = \"{0}\"" + Environment.NewLine, xmlItem.Element("name").Value);
fileData.AppendFormat("description = \"{0}\"" + Environment.NewLine, xmlItem.Element("description").Value);
// Keywords
var keywords = xmlItem.Element("keywords").Elements("keyword").Select(e => e.Value).Where(e => !string.IsNullOrWhiteSpace(e));
if (keywords.Any())
{
fileData.AppendFormat("keywords = [\"{0}\"]" + Environment.NewLine, string.Join("\", \"", keywords));
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("parameters").Value))
{
fileData.AppendFormat("statementParameters = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("parameters").Value.Replace("\"", "\\\""));
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("select").Value))
{
fileData.AppendFormat("statementSelect = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("select").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("using").Value))
{
fileData.AppendFormat("statementUsing = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("using").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("into").Value))
{
fileData.AppendFormat("statementInto = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("into").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("from").Value))
{
fileData.AppendFormat("statementFrom = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("from").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("where").Value))
{
fileData.AppendFormat("statementWhere = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("where").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("groupBy").Value))
{
fileData.AppendFormat("statementGroupby = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("groupBy").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("having").Value))
{
fileData.AppendFormat("statementHaving = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("having").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("statement").Element("orderBy").Value))
{
fileData.AppendFormat("statementOrderby = \"{0}\"" + Environment.NewLine, xmlItem.Element("statement").Element("orderBy").Value);
}
if (!string.IsNullOrWhiteSpace(xmlItem.Element("notes").Value))
{
fileData.AppendFormat("notes = \"{0}\"" + Environment.NewLine, xmlItem.Element("notes").Value.Replace("\"", "\\\""));
}
/*
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();