我这里有一个扁平化的XSD:http://pastebin.com/tQVSH9Jp
我有一个“替换”的XSLT脚本,我正在对它运行,以修复它的XSD.exe (它忽略引用的元素),但作为结果的XSD缺少一些属性。(UniqueID_Type中不存在ID)。
有没有人能提供一个能够正确执行这些替换的XSLT脚本,或者甚至提供另一种解决方案?
发布于 2012-04-12 10:25:57
有趣的是,有人建议编写自己的xsd.exe,也要依赖XmlSchemaImporter……首先,我不认为这是一项微不足道的任务;其次,缺少属性的问题来自XmlSchemaImporter;ImportAttributeGroupMembers中有一个错误:它不是寻找XmlSchemaAttributeGroupRef,而是检查XmlSchemaAttributeGroup (下面摘自Reflector):
private void ImportAttributeGroupMembers(XmlSchemaAttributeGroup group, string identifier, CodeIdentifiers members, CodeIdentifiers membersScope, string ns)
{
for (int i = 0; i < group.Attributes.Count; i++)
{
object obj2 = group.Attributes[i];
if (obj2 is XmlSchemaAttributeGroup)
{
...
}
else if (obj2 is XmlSchemaAttribute)
{
...
}
}
...
}还有一个类似的实用程序,xsd2code,在讨论XML Schema重构(XSR)之前,我会尝试使用原始的XSD。
如果你想走这条路,我推荐XSR的QTAssistant (我和它有关联)。我已经使用最新版本(4.0.21)试用了您的XSD,它可以正常工作。我已经发布了结果here。
对于您指出有缺陷的片段(我只是显示字段),使用XSD.exe生成的代码现在显示ID属性的idField:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.opentravel.org/OTA/2003/05")]
public partial class UniqueID_Type {
private CompanyNameType companyNameField;
private string uRLField;
private string typeField;
private string instanceField;
private string idField;
private string iD_ContextField;
...
}特定于您的设置的是必须设置为true的InlineAttributeGroups:

如果您对使用QTAssistant进行重构的更多细节感兴趣,请查看this post,等等。无论如何,我已经发布了整个重构的模式,请随意使用它……
https://stackoverflow.com/questions/10109689
复制相似问题