From ea549eec9f3ac40ff7b71990a27da80a4a704ce2 Mon Sep 17 00:00:00 2001 From: ocvist Date: Wed, 11 Mar 2015 11:15:09 -0400 Subject: [PATCH 1/6] Create FileParse.csx Simple example of XML file parse script. --- XML/FileParse.csx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 XML/FileParse.csx diff --git a/XML/FileParse.csx b/XML/FileParse.csx new file mode 100644 index 0000000..b1f0b11 --- /dev/null +++ b/XML/FileParse.csx @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; + +var test = XElement.Load(@"C:\Users\Public\Documents\ScriptCS\schema.xml"); +var data = (from nodes in test.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); +} From a82c2d17ff26f4b3452367a1c6b360a5c686c0bc Mon Sep 17 00:00:00 2001 From: ocvist Date: Mon, 16 Mar 2015 12:48:20 -0400 Subject: [PATCH 2/6] Update FileParse.csx --- XML/FileParse.csx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/XML/FileParse.csx b/XML/FileParse.csx index b1f0b11..e46408d 100644 --- a/XML/FileParse.csx +++ b/XML/FileParse.csx @@ -3,13 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Xml.Linq; -var test = XElement.Load(@"C:\Users\Public\Documents\ScriptCS\schema.xml"); -var data = (from nodes in test.Descendants() - select new - { - Name = nodes.Attributes("name"), - Ref = nodes.Attributes("ref") - }); +var data = (from nodes in XElement.Load("schema.xml").Descendants() + select new + { + Name = nodes.Attributes("name"), + Ref = nodes.Attributes("ref") + }); var list = new List(); From e1203e48f3f372fd746a94b893ac8cd5894468db Mon Sep 17 00:00:00 2001 From: ocvist Date: Mon, 16 Mar 2015 12:49:11 -0400 Subject: [PATCH 3/6] Create schema.xml --- XML/schema.xml | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 XML/schema.xml 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 0d0adfa956ebd7b6532f7bc1e09bd23ba564ea1b Mon Sep 17 00:00:00 2001 From: ocvist Date: Mon, 16 Mar 2015 12:57:00 -0400 Subject: [PATCH 4/6] Create ReadMe.md --- XML/ReadMe.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 XML/ReadMe.md diff --git a/XML/ReadMe.md b/XML/ReadMe.md new file mode 100644 index 0000000..710c106 --- /dev/null +++ b/XML/ReadMe.md @@ -0,0 +1,15 @@ +# Parsing XML (with output to file) with scriptcs + +## Running the sample +* Make sure you have ScriptCS installed. +* 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. From 42bb0d8a3c1a10c4c9932f54b7640e7aad038e85 Mon Sep 17 00:00:00 2001 From: ocvist Date: Mon, 16 Mar 2015 13:00:49 -0400 Subject: [PATCH 5/6] Rename ReadMe.md to README.md --- XML/{ReadMe.md => README.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename XML/{ReadMe.md => README.md} (100%) diff --git a/XML/ReadMe.md b/XML/README.md similarity index 100% rename from XML/ReadMe.md rename to XML/README.md From 81394216cba50b0a5a1ffcf930e220d1da81c91e Mon Sep 17 00:00:00 2001 From: ocvist Date: Mon, 16 Mar 2015 13:01:27 -0400 Subject: [PATCH 6/6] Update README.md --- XML/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/XML/README.md b/XML/README.md index 710c106..1786289 100644 --- a/XML/README.md +++ b/XML/README.md @@ -1,7 +1,7 @@ # Parsing XML (with output to file) with scriptcs ## Running the sample -* Make sure you have ScriptCS installed. +* 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.