diff --git a/XML/FileParse.csx b/XML/FileParse.csx new file mode 100644 index 0000000..e46408d --- /dev/null +++ b/XML/FileParse.csx @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; + +var data = (from nodes in XElement.Load("schema.xml").Descendants() + select new + { + Name = nodes.Attributes("name"), + Ref = nodes.Attributes("ref") + }); + +var list = new List(); + +foreach (var item in data) +{ + if (item.Name.FirstOrDefault() != null) list.Add(item.Name.FirstOrDefault().Value); + if (item.Ref.FirstOrDefault() != null) list.Add(item.Ref.FirstOrDefault().Value); +} + +foreach (var item in list.Distinct().OrderBy(i => i.ToString())) { + Console.WriteLine(item); +} diff --git a/XML/README.md b/XML/README.md new file mode 100644 index 0000000..1786289 --- /dev/null +++ b/XML/README.md @@ -0,0 +1,15 @@ +# Parsing XML (with output to file) with scriptcs + +## Running the sample +* Make sure scriptcs is [installed](https://github.com/scriptcs/scriptcs-samples/blob/master/README.md) +* Make sure FileParse.csx and schema.xml files are in the same folder. +* Run "scriptcs FileParse.csx > output.txt" in command prompt. +* Output.txt file should appear in the same folder as the script and schema files. +* Remove "> output.txt" from command to output result to screen. + +## Comments + +The need for this example came about when we needed a working proof of concept of +command line driven linq query our DBAs could use as part of SQL job chain. We have data +stored in XML form and needed a flexible parsing solution that can be edited without +the need to compile anything that does the parsing. diff --git a/XML/schema.xml b/XML/schema.xml new file mode 100644 index 0000000..5ef7a90 --- /dev/null +++ b/XML/schema.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +