Ejemplo n.º 1
0
        public bool IsQuestValid(IQuest quest)
        {
            bool isValid = true;

            var xml = new XmlDocument();
            xml.LoadXml(quest.WholeQuestXml);
            var names = new XmlNamespaceManager(xml.NameTable);
            names.AddNamespace("x", "http://www.martinvseticka.eu/SoTh");
            XmlNodeList nodes = xml.SelectNodes("/x:SokobanQuest/x:Round/x:GameObjects/*", names);

            XmlValidator xmlValidator = new XmlValidator();
            xmlValidator.AddSchema(null, Sokoban.View.GameDocsComponents.Properties.Resources.QuestSchema); // main schema

            // We have to prevent to adding a schema twice to the collection of schemas (to xmlValidator)
            // Therefore we use Dictonary and then we extract each schema exactly once.
            Dictionary<string, string> schemas = new Dictionary<string, string>();

            // schemas from plugins
            foreach (XmlNode node in nodes)
            {
                schemas[node.Name] = gameRepository.PluginService.GetPluginSchema(node.Name);
            }

            foreach (KeyValuePair<string, string> pair in schemas)
            {
                xmlValidator.AddSchema(null, pair.Value);
            }

            isValid = xmlValidator.IsValid(quest.WholeQuestXml);
            questValidationErrorMessage = (isValid) ? "" : xmlValidator.GetErrorMessage();

            return isValid;
        }
Ejemplo n.º 2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            DebuggerIX.Start(DebuggerMode.OutputWindow);

            string instance = XMLSchemaTest.Properties.Resources.TestQuest;
            string schema1 = XMLSchemaTest.Properties.Resources.QuestSchema;
            string schema2 = XMLSchemaTest.Properties.Resources.PluginSchema;

            XmlValidator validator = new XmlValidator();

            validator.AddSchema(null, schema1);
            validator.AddSchema(null, schema2);
            bool isValid = validator.IsValid(instance);

            textBlock.Text = "Scheme is: " + (isValid ? "Valid" : "Not valid! Error: " + validator.GetErrorMessage());

            /*var xml = new XmlDocument();
            xml.LoadXml(instance);
            var names = new XmlNamespaceManager(xml.NameTable);
            names.AddNamespace("x", "http://www.martinvseticka.eu/SoTh");
            //var nodes = xml.SelectNodes("/SokobanQuest/*", names);
            var nodes = xml.SelectNodes("/x:SokobanQuest/x:Round/x:GameObjects/*", names);
            */

            DebuggerIX.Close();
        }