@ -32,11 +32,13 @@ namespace ICSharpCode.XmlEditor
XmlView xmlView = XmlView . ActiveXmlView ;
XmlView xmlView = XmlView . ActiveXmlView ;
if ( xmlView ! = null ) {
if ( xmlView ! = null ) {
// Create a schema based on the xml.
// Create a schema based on the xml.
string schema = xmlView . CreateSchema ( ) ;
string [ ] schemas = xmlView . InferSchema ( ) ;
if ( schema ! = null ) {
if ( schemas ! = null ) {
// Create a new file and display the generated schema.
// Create a new file for each generated schema.
string fileName = GenerateSchemaFileName ( xmlView . TextEditorControl . FileName ) ;
for ( int i = 0 ; i < schemas . Length ; + + i ) {
OpenNewXmlFile ( fileName , schema ) ;
string fileName = GenerateSchemaFileName ( xmlView . TextEditorControl . FileName , i + 1 ) ;
OpenNewXmlFile ( fileName , schemas [ i ] ) ;
}
}
}
}
}
}
}
@ -50,22 +52,16 @@ namespace ICSharpCode.XmlEditor
}
}
/// <summary>
/// <summary>
/// Generates an xsd filename based on the name of the original xml
/// Generates an xsd filename based on the name of the original xml file.
/// file. If a file with the same name is already open in SharpDevelop
/// then a new name is generated (e.g. MyXml1.xsd).
/// </summary>
/// </summary>
string GenerateSchemaFileName ( string xmlFileName )
string GenerateSchemaFileName ( string xmlFileName , int count )
{
{
string baseFileName = Path . GetFileNameWithoutExtension ( xmlFileName ) ;
string baseFileName = Path . GetFileNameWithoutExtension ( xmlFileName ) ;
string schemaFileName = String . Concat ( baseFileName , ".xsd" ) ;
string schemaFileName = String . Concat ( baseFileName , ".xsd" ) ;
if ( count = = 1 ) {
int count = 1 ;
return schemaFileName ;
while ( FileService . IsOpen ( schemaFileName ) ) {
schemaFileName = String . Concat ( baseFileName , count . ToString ( ) , ".xsd" ) ;
+ + count ;
}
}
return schemaFileName = String . Concat ( baseFileName , count . ToString ( ) , ".xsd" ) ;
return schemaFileName ;
}
}
}
}
}
}