3

我在http://www.w3.org/2001/XMLSchema.xsd下载了 XML Schemas for XML Schemas 。

然后我使用XSD.EXE从下载的文件创建一个类。我打电话给全班schema.cs

然后我执行了这行代码:

XmlSerializer serializer = new XmlSerializer(typeof(schema));

并得到这个错误:

命名空间“http://www.w3.org/2001/XMLSchema”中的 XML 元素“注释”已存在于当前范围内。

如何在不破坏架构的情况下找到重复元素并修复它?

4

2 回答 2

1

我认为生成的类有缺陷。

我更改了属性以修复第一个错误,但发现了一个新错误。

/// <remarks/>
//[System.Xml.Serialization.XmlElementAttribute("annotation", typeof(annotation))]
[System.Xml.Serialization.XmlElementAttribute("Items", typeof(annotation))]
[System.Xml.Serialization.XmlElementAttribute("import", typeof(import))]
[System.Xml.Serialization.XmlElementAttribute("include", typeof(include))]
[System.Xml.Serialization.XmlElementAttribute("redefine", typeof(redefine))]
public openAttrs[] Items {
    get {
        return this.itemsField;
    }
    set {
        this.itemsField = value;
    }
}
于 2010-10-27T18:36:04.903 回答
0

因为注释元素只是注释,您可以尝试简单地将所有这些过滤掉。只需首先将 XML 加载到 anXDocument中并删除所有注释元素。

于 2010-10-27T17:27:24.210 回答