?? xmlvalidatingpanel.cs
字號:
#endif
TextAreaTabPage tab = this.MainForm.GetTabPageByFileName(dtdFileName);
dtdStream = tab.TextAreaControl.Document.GetStream();
resolver = new FileXMLResolver(dtdStream, true);
}
}
this.XMLValidateWithDTD(this.inputTextAreaTabPage.TextAreaControl.FileName, resolver, this.inputTextAreaTabPage.TextAreaControl.Document.GetStream());
break;
case ValidationType.Schema:
Stream schemaStream = null;
if (this.externalSchemaFileName != null)
{
schemaStream = new FileStream(this.externalSchemaFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
}
else
{
string schemaFileName = (string) this.comboSchemaFileNames[ this.comboSchema.SelectedIndex ];
#if DEBUG
System.Diagnostics.Debug.Assert(schemaFileName != null);
System.Diagnostics.Debug.Assert(schemaFileName != String.Empty);
#endif
TextAreaTabPage tab = this.MainForm.GetTabPageByFileName(schemaFileName);
schemaStream = tab.TextAreaControl.Document.GetStream();
}
this.XMLValidate(this.inputTextAreaTabPage.TextAreaControl.FileName, vType, schemaStream, this.inputTextAreaTabPage.TextAreaControl.Document.GetStream());
break;
}
this.MainForm.OutputPanel.AppendTextLine("\r\n---------------------- Done ----------------------\r\n");
}
// -------------------------------------------------------------------------
/// <summary>
/// Validuje dokument.
/// </summary>
/// <returns>true = ak je dokument validny</returns>
private bool XMLValidate(string fullFileName, ValidationType vType, Stream schemaStream, Stream inputStream)
{
this.isValid = true;
this.numOfErrors = 0;
XmlValidatingReader xsd = null;
try
{
XmlTextReader xml = new XmlTextReader(inputStream);
xsd = new XmlValidatingReader(xml);
xsd.ValidationType = vType;
xsd.XmlResolver = null;
if (schemaStream != null)
{
XmlTextReader schemaReader = new XmlTextReader(schemaStream);
xsd.Schemas.Add(null, schemaReader);
}
// Validacne chyby budeme prijimat tu...
xsd.ValidationEventHandler += new ValidationEventHandler(ValidationErrorHandler);
// Tu prebehne validacia
while (xsd.Read())
{
}
xsd.Close();
if (this.isValid == true)
{
this.MainForm.OutputPanel.AppendTextLine("Document is VALID");
}
else
{
this.MainForm.OutputPanel.AppendTextLine("Document is INVALID");
}
}
catch (UnauthorizedAccessException a)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("UnauthorizedAccessException a");
#endif
this.MainForm.OutputPanel.AppendTextLine(a.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, a.Message, fullFileName, 0, 0);
}
catch (XmlException a)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("XmlException a");
#endif
this.MainForm.OutputPanel.AppendTextLine(a.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, a.Message, fullFileName, a.LineNumber, a.LinePosition);
}
catch (Exception a)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("Exception a");
#endif
this.MainForm.OutputPanel.AppendTextLine(a.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, a.Message, fullFileName, 0, 0);
}
finally
{
if (xsd != null)
{
xsd.Close();
}
}
return this.isValid;
}
// -------------------------------------------------------------------------
/// <summary>
/// Validuje dokument ci splna zadane DTD
/// </summary>
/// <returns>true = ak je dokument validny</returns>
private bool XMLValidateWithDTD(string fullFileName, System.Xml.XmlResolver resolver, Stream inputStream)
{
this.isValid = true;
this.numOfErrors = 0;
XmlValidatingReader xsd = null;
try
{
XmlTextReader xml = new XmlTextReader(inputStream);
xsd = new XmlValidatingReader(xml);
xsd.ValidationType = ValidationType.DTD;
xsd.XmlResolver = resolver;
// Validacne chyby budeme prijimat tu...
xsd.ValidationEventHandler += new ValidationEventHandler(ValidationErrorHandler);
// Tu prebehne validacia
while (xsd.Read())
{
}
xsd.Close();
if (this.isValid == true)
{
this.MainForm.OutputPanel.AppendTextLine("Document is VALID");
}
else
{
this.MainForm.OutputPanel.AppendTextLine("Document is INVALID");
}
}
catch (UnauthorizedAccessException a)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("UnauthorizedAccessException a");
#endif
this.MainForm.OutputPanel.AppendTextLine(a.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, a.Message, fullFileName, 0, 0);
}
catch (XmlException a)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("XmlException a");
#endif
this.MainForm.OutputPanel.AppendTextLine(a.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, a.Message, fullFileName, a.LineNumber, a.LinePosition);
}
catch (Exception a)
{
#if DEBUG
System.Diagnostics.Debug.WriteLine("Exception a");
#endif
this.MainForm.OutputPanel.AppendTextLine(a.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, a.Message, fullFileName, 0, 0);
}
finally
{
if (xsd != null)
{
xsd.Close();
}
}
return this.isValid;
}
// -------------------------------------------------------------------------
/// <summary>
/// Tato vynimka je vyvolavana pri chybe 'validovania'
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private void ValidationErrorHandler(object sender, System.Xml.Schema.ValidationEventArgs args)
{
if (this.numOfErrors < 20)
{
this.isValid = false;
this.MainForm.OutputPanel.AppendTextLine(args.Message);
this.MainForm.TaskListPanel.AddTask(TaskType.Error, args.Message, this.MainForm.ActualTextAreaControl.FileName, args.Exception.LineNumber, args.Exception.LinePosition);
this.numOfErrors++;
}
}
// -------------------------------------------------------------------------
/// <summary>
/// 'Rozbalenie' combo-boxu na vyber XML Schema suboru
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DropDown_comboSchema(object sender, System.EventArgs e)
{
this.externalSchemaFileName = null;
this.comboSchema.Items.Clear();
this.comboSchemaFileNames.Clear();
this.labelSchema.Text = "[internal]";
FileInfo fileInfo;
foreach (TextAreaTabPage txtArea in this.MainForm.TabPages)
{
if (txtArea.IsNewFile == true)
{
continue;
}
fileInfo = new FileInfo(txtArea.TitleToShow);
if (fileInfo.Extension.ToLower() == ".xsd")
{
this.comboSchema.Items.Insert(0, txtArea.TitleToShow);
this.comboSchemaFileNames.Insert(0, txtArea.TextAreaControl.FileName);
}
else
{
this.comboSchema.Items.Add(txtArea.TitleToShow);
this.comboSchemaFileNames.Add(txtArea.TextAreaControl.FileName);
}
}
}
// -------------------------------------------------------------------------
/// <summary>
/// 'Rozbalenie' combo-boxu na vyber DTD suboru
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DropDown_comboDTD(object sender, System.EventArgs e)
{
this.externalDTDFileName = null;
this.comboDTD.Items.Clear();
this.comboDTDFileNames.Clear();
this.labelDTD.Text = "[internal]";
FileInfo fileInfo;
foreach (TextAreaTabPage txtArea in this.MainForm.TabPages)
{
if (txtArea.IsNewFile == true)
{
continue;
}
fileInfo = new FileInfo(txtArea.TitleToShow);
if (fileInfo.Extension.ToLower() == ".dtd")
{
this.comboDTD.Items.Insert(0, txtArea.TitleToShow);
this.comboDTDFileNames.Insert(0, txtArea.TextAreaControl.FileName);
}
else
{
this.comboDTD.Items.Add(txtArea.TitleToShow);
this.comboDTDFileNames.Add(txtArea.TextAreaControl.FileName);
}
}
}
// -------------------------------------------------------------------------
/// <summary>
/// Zmenilo sa zaskrtnutie niektoreho radiobuttonu - POZOR vyvolava sa pri jednom
/// zaskrtnuti dva-krat.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckedChanged_radioButtons(object sender, System.EventArgs e)
{
this.labelSchema.Enabled = this.buttonSchemaLoad.Enabled =
this.comboSchema.Enabled = this.radioButtonSchema.Checked;
this.labelDTD.Enabled = this.buttonDTDLoad.Enabled =
this.comboDTD.Enabled = this.buttonEmbeddedDTD.Enabled = this.radioButtonDTD.Checked;
}
} // public class XMLValidatingPanel : ...
} // namespace XML_editor.DockingPanels
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -