private void LoadSchema(string schemaFilename) { Cursor = Cursors.WaitCursor; this.mruManager.AddRecentFile(schemaFilename); CleanupUserInterface(false); UpdateTitle(schemaFilename); schema.LoadSchema(schemaFilename); UpdateActionsState(); foreach (XSDObject xsdObject in schema.Elements) { this.listViewElements.Items.Add(new ListViewItem(new string[] { xsdObject.Name, xsdObject.Type, xsdObject.NameSpace })).Tag = xsdObject; this.toolStripComboBoxSchemaElement.Items.Add(xsdObject); } Cursor = Cursors.Default; if (this.schema.LoadError.Count > 0) { ErrorReportForm errorReportForm = new ErrorReportForm(); errorReportForm.Errors = this.schema.LoadError; errorReportForm.ShowDialog(this); } this.diagram.ElementsByName = this.schema.ElementsByName; if (this.schema.FirstElement != null) this.toolStripComboBoxSchemaElement.SelectedItem = this.schema.FirstElement; else this.toolStripComboBoxSchemaElement.SelectedIndex = 0; tabControlView_Selected(null, null); this.tabControlView.SuspendLayout(); foreach (string filename in this.schema.XsdFilenames) { string fullPath = filename; Control browser = null; if (webBrowserSupported) browser = new WebBrowser(); else browser = new System.Windows.Forms.TextBox() { Multiline = true, ReadOnly = true, ScrollBars = ScrollBars.Both }; browser.Dock = DockStyle.Fill; browser.TabIndex = 0; try { new Uri(filename); } catch { fullPath = Path.GetFullPath(filename); } TabPage tabPage = new TabPage(Path.GetFileNameWithoutExtension(filename)); tabPage.Tag = fullPath; tabPage.ToolTipText = fullPath; tabPage.Controls.Add(browser); tabPage.UseVisualStyleBackColor = true; this.tabControlView.TabPages.Add(tabPage); this.hashtableTabPageByFilename[filename] = tabPage; } this.tabControlView.ResumeLayout(); //currentLoadedSchemaFilename = schemaFilename; }
private void validateXMLFileToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { try { Cursor = Cursors.WaitCursor; validationErrorMessages.Clear(); StreamReader streamReader = new StreamReader(openFileDialog.FileName); string xmlSource = streamReader.ReadToEnd(); streamReader.Close(); //XmlDocument x = new XmlDocument(); //x.LoadXml(xmlSource); XmlReaderSettings settings = new XmlReaderSettings(); settings.CloseInput = true; settings.ValidationType = ValidationType.Schema; settings.ProhibitDtd = false; settings.XmlResolver = null; settings.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation ; //| XmlSchemaValidationFlags.AllowXmlAttributes; //settings.Schemas.Add("http://www.collada.org/2005/11/COLLADASchema", currentLoadedSchemaFilename); //settings.Schemas.Add(null, currentLoadedSchemaFilename); // = sc; List<string> schemas = new List<string>(schema.XsdFilenames); schemas.Reverse(); foreach (string schemaFilename in schemas) { try { settings.Schemas.Add(null, schemaFilename); } catch (Exception ex) { validationErrorMessages.Add(string.Format("Error while parsing {0}, Message: {1}", schemaFilename, ex.Message)); } } StringReader r = new StringReader(xmlSource); using (XmlReader validatingReader = XmlReader.Create(r, settings)) { while (validatingReader.Read()) { /* just loop through document */ } } Cursor = Cursors.Default; ErrorReportForm errorReportForm = new ErrorReportForm(); errorReportForm.Errors = validationErrorMessages; errorReportForm.ShowDialog(this); } catch (Exception ex) { Cursor = Cursors.Default; validationErrorMessages.Add(string.Format("Error while validating {0}, Message: {1}", openFileDialog.FileName, ex.Message)); //MessageBox.Show("Cannot validate: " + ex.Message); ErrorReportForm errorReportForm = new ErrorReportForm(); errorReportForm.Errors = validationErrorMessages; errorReportForm.ShowDialog(this); } Cursor = Cursors.Default; if (validationErrorMessages.Count == 0) MessageBox.Show("No issue found"); } }