|
|
|
@ -8,6 +8,7 @@ |
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
using System.Collections.ObjectModel; |
|
|
|
|
|
|
|
using System.Data; |
|
|
|
using System.Drawing; |
|
|
|
using System.Drawing; |
|
|
|
using System.Drawing.Printing; |
|
|
|
using System.Drawing.Printing; |
|
|
|
using System.IO; |
|
|
|
using System.IO; |
|
|
|
@ -371,6 +372,32 @@ namespace ICSharpCode.XmlEditor |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Creates a schema based on the xml content.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
/// <returns>A generated schema or null if the xml content is not
|
|
|
|
|
|
|
|
/// well formed.</returns>
|
|
|
|
|
|
|
|
public string CreateSchema() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
TaskService.ClearExceptCommentTasks(); |
|
|
|
|
|
|
|
if (IsWellFormed) { |
|
|
|
|
|
|
|
string schema; |
|
|
|
|
|
|
|
using (DataSet dataSet = new DataSet()) { |
|
|
|
|
|
|
|
dataSet.ReadXml(new StringReader(Text), XmlReadMode.InferSchema); |
|
|
|
|
|
|
|
EncodedStringWriter writer = new EncodedStringWriter(xmlEditor.TextEditorProperties.Encoding); |
|
|
|
|
|
|
|
XmlTextWriter xmlWriter = CreateXmlTextWriter(writer); |
|
|
|
|
|
|
|
dataSet.WriteXmlSchema(xmlWriter); |
|
|
|
|
|
|
|
schema = writer.ToString(); |
|
|
|
|
|
|
|
writer.Close(); |
|
|
|
|
|
|
|
xmlWriter.Close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return schema; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
ShowErrorList(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Finds the definition of the xml element or attribute under the cursor
|
|
|
|
/// Finds the definition of the xml element or attribute under the cursor
|
|
|
|
/// in the corresponding schema and then displays that schema and the definition
|
|
|
|
/// in the corresponding schema and then displays that schema and the definition
|
|
|
|
@ -946,15 +973,7 @@ namespace ICSharpCode.XmlEditor |
|
|
|
reader.WhitespaceHandling = WhitespaceHandling.None; |
|
|
|
reader.WhitespaceHandling = WhitespaceHandling.None; |
|
|
|
|
|
|
|
|
|
|
|
StringWriter indentedXmlWriter = new StringWriter(); |
|
|
|
StringWriter indentedXmlWriter = new StringWriter(); |
|
|
|
XmlTextWriter writer = new XmlTextWriter(indentedXmlWriter); |
|
|
|
XmlTextWriter writer = CreateXmlTextWriter(indentedXmlWriter); |
|
|
|
if (xmlEditor.TextEditorProperties.ConvertTabsToSpaces) { |
|
|
|
|
|
|
|
writer.Indentation = xmlEditor.TextEditorProperties.TabIndent; |
|
|
|
|
|
|
|
writer.IndentChar = ' '; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
writer.Indentation = 1; |
|
|
|
|
|
|
|
writer.IndentChar = '\t'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
writer.Formatting = Formatting.Indented; |
|
|
|
|
|
|
|
writer.WriteNode(reader, false); |
|
|
|
writer.WriteNode(reader, false); |
|
|
|
writer.Flush(); |
|
|
|
writer.Flush(); |
|
|
|
|
|
|
|
|
|
|
|
@ -966,6 +985,20 @@ namespace ICSharpCode.XmlEditor |
|
|
|
return indentedText; |
|
|
|
return indentedText; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XmlTextWriter CreateXmlTextWriter(TextWriter textWriter) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
XmlTextWriter writer = new XmlTextWriter(textWriter); |
|
|
|
|
|
|
|
if (xmlEditor.TextEditorProperties.ConvertTabsToSpaces) { |
|
|
|
|
|
|
|
writer.Indentation = xmlEditor.TextEditorProperties.TabIndent; |
|
|
|
|
|
|
|
writer.IndentChar = ' '; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
writer.Indentation = 1; |
|
|
|
|
|
|
|
writer.IndentChar = '\t'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
writer.Formatting = Formatting.Indented; |
|
|
|
|
|
|
|
return writer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Checks that the xml in this view is well-formed.
|
|
|
|
/// Checks that the xml in this view is well-formed.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
@ -976,11 +1009,7 @@ namespace ICSharpCode.XmlEditor |
|
|
|
Document.LoadXml(Text); |
|
|
|
Document.LoadXml(Text); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} catch(XmlException ex) { |
|
|
|
} catch(XmlException ex) { |
|
|
|
string fileName = FileName; |
|
|
|
AddTask(xmlEditor.FileName, ex.Message, ex.LinePosition - 1, ex.LineNumber - 1, TaskType.Error); |
|
|
|
if (fileName == null || fileName.Length == 0) { |
|
|
|
|
|
|
|
fileName = TitleName; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
AddTask(fileName, ex.Message, ex.LinePosition - 1, ex.LineNumber - 1, TaskType.Error); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|