2012-12-04 65 views
2

有一組的,其可以是指彼此(與include/import/redefine tags)N XSD文件。任務是本組N XSD的文件轉換成M個XSD的文件的最低可能數目。轉換意味着就地插入包含的文件在可能情況下,解析引用等庫XML模式壓扁

此功能成功地工作在一些用戶界面的XML編輯器。

是否有任何免費或商業庫(本地或.NET),讓我執行XML架構扁平化?或者,也許有以扁平化算法一些參考?

回答

2

我不認爲你需要的庫。使用標準的.NET架構類這是一個轉換XSD與一羣包括到一個單一的一個代碼:

static private void ResolveExternal(
    XmlSchema rootSchema, 
    XmlSchema curSchema, 
    List<string> processed 
) 
{ 
    // Loop on all the includes 
    foreach (XmlSchemaExternal external in curSchema.Includes) { 
    // Avoid processing twice the same include file 
    if (!processed.Contains(external.SchemaLocation)) { 
     processed.Add(external.SchemaLocation); 
     XmlSchema cur = external.Schema; 
     // Recursive calls to handle includes inside the include 
     ResolveExternal(rootSchema, cur, processed); 
     // Move the items from the included schema to the root one 
     foreach (XmlSchemaObject item in cur.Items) { 
     rootSchema.Items.Add(item); 
     } 
    } 
    } 
    curSchema.Includes.Clear(); 
} // ResolveExternal 

static public void ResolveExternal(XmlSchema schema) 
{ 
    List<string> processed = new List<string>(); 
    ResolveExternal(schema, schema, processed); 
} // ResolveExternal 

你應該能夠處理的進口和以類似的方式重新定義。