using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Namespaces added manually
using System.Xml; // XmlReader, XmlDocument and XmlReaderSetting classes
using System.Xml.Schema; // XmlSchemaValidationFlags class
using System.IO; // File class
namespace DisplayChessGame
{
class DisplayChess
{
// Private member variables
private static string xmlFile = "";
private static bool valid_xml = true;
static void Main(string[] args)
{
try
{
// Display a title
Console.WriteLine("WHMIS 2015 Label Information\n----------------------------\n");
// Get the name of the XML file
if (args.Count() > 0 && File.Exists(args[0]))
{
// Getting XML file name from the command line
xmlFile = args[0];
}
else
{
// Ask the user to input the file name
bool invalidFile = true;
do
{
Console.Write("Enter the path + name of your XML file: ");
xmlFile = Console.ReadLine();
if (!File.Exists(xmlFile))
Console.WriteLine("ERROR: The file '{0}' can't be found!", xmlFile);
else
invalidFile = false;
} while ( invalidFile );
// Print a blank line
Console.WriteLine();
}
// Set the validation settings
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
ValidationEventHandler handler
= new ValidationEventHandler(ValidationCallback);
settings.ValidationEventHandler += handler;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
// Create the XmlReader object and read/validate the XML file
XmlReader reader = XmlReader.Create(xmlFile, settings);
// Load the xml into the DOM
XmlDocument doc = new XmlDocument();
doc.Load(reader);
if (valid_xml)
{
???????????????????????????????????
???????????????????????????????????
???????????????????????????????????
}
}
catch (XmlException ex)
{
Console.WriteLine("ERROR: " + ex.Message);
}
// Hold the console window open until a key is pressed
Console.WriteLine("Press any key to quit.");
Console.ReadKey();
} // end Main()
// Callback method to display validation errors and warnings
private static void ValidationCallback(object sender, ValidationEventArgs args)
{
if (args.Severity == XmlSeverityType.Warning)
Console.WriteLine("WARNING: " + args.Message);
else
{
Console.WriteLine("SCHEMA ERROR: " + args.Message);
valid_xml = false;
}
} // end ValidationCallback()
} // end class
} // end namespace