I downloaded the XML Schema for XML Schemas at http://www.w3.org/2001/XMLSchema.xsd.
I then used XSD.EXE to create a class from the downloaded file. I called the class schema.cs
.
I then executed this line of code:
XmlSerializer serializer = new XmlSerializer(typeof(schema));
and got this error:
The XM开发者_运维问答L element 'annotation' from namespace 'http://www.w3.org/2001/XMLSchema' is already present in the current scope.
How do I find the duplicate element and fix it, without breaking the schema?
I think the generated class has flaws.
I changed the attribute to fix the first error but a new error is discovered.
/// <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;
}
}
Because the annotate elements are just comments, you could try simply filtering all of these out. Just first load the XML into an XDocument
and remove all annotate elements.
精彩评论