Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please see the code below that will write to the console the file name and associated warning message.</p> <p>This approach will deserialise your XML into .NET objects that are ready to use.</p> <p>A small tip - try to avoid using too many attributes in your XML. Consider converting the ScriptFile attributes to elements to increase readability =] (You will need to modify the code to reflect the change if you choose to make it - change the XmlAttribute attributes to XmlElement).</p> <p>Good luck!</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Xml.Linq; using System.Xml.Serialization; namespace ConsoleApplication1 { public class Program { static void Main(string[] args) { string input = @"&lt;ScriptFileNames&gt; &lt;SqlEye&gt; &lt;ScriptFile Name='_ws_CommandHistory_AllHistory.sql' Type='SP' SqlEyeAnalysisTime='00:00:01.7817594' FxCopAnalysisTime='00:00:00.2253670' FxCopWarningCount='0' SqlEyeWarningCount='2'&gt; &lt;SqlEyeWarnings&gt; &lt;SqlEyeWarning message='SD004: Check for existence object then Drop statement before create statement' /&gt; &lt;SqlEyeWarning message='SP001: Set NoCount statement missing or it should be ON.' /&gt; &lt;/SqlEyeWarnings&gt; &lt;/ScriptFile&gt; &lt;/SqlEye&gt; &lt;/ScriptFileNames&gt;"; XDocument doc = XDocument.Parse(input); XmlSerializer serialiser = new XmlSerializer(typeof(ScriptFileNames)); ScriptFileNames scriptNames = (ScriptFileNames)serialiser.Deserialize(doc.CreateReader()); foreach (SqlEyeWarning warning in scriptNames.SqlEye.ScriptFile.SqlEyeWarnings) { Console.WriteLine(scriptNames.SqlEye.ScriptFile.Name + "\t" + warning.Message); } Console.ReadLine(); } [XmlRoot] public class ScriptFileNames { [XmlElement("SqlEye")] public SqlEye SqlEye { get; set; } } public class SqlEye { [XmlElement("ScriptFile")] public ScriptFile ScriptFile { get; set; } } public class ScriptFile { [XmlArray("SqlEyeWarnings")] [XmlArrayItem("SqlEyeWarning", typeof(SqlEyeWarning))] public SqlEyeWarning[] SqlEyeWarnings { get; set; } [XmlAttribute("Name")] public string Name { get; set; } [XmlAttribute("Type")] public string Type { get; set; } [XmlAttribute("SqlEyeAnalysisTime")] public string SqlEyeAnalysisTime { get; set; } [XmlAttribute("FxCopAnalysisTime")] public string FxCopAnalysisTime { get; set; } [XmlAttribute("FxCopWarningCount")] public string FxCopWarningCount { get; set; } [XmlAttribute("SqlEyeWarningCount")] public string SqlEyeWarningCount { get; set; } } public class SqlEyeWarning { [XmlAttribute("message")] public string Message { get; set; } } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload