3
votes

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 XML 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?

2
It may be that the exception has a line and position number. Could you add these? - Pieter van Ginkel
@Pieter: The exception didn't include a line number, and neither did the inner exception. - Robert Harvey
And you have no hint at all what annotation throws? I have looked at the XSD and it looks like there are many scopes where there are multiple annotations. - Pieter van Ginkel
@Pieter: No I don't. That's the basic problem, is visibility. - Robert Harvey
@0xA3: I'm trying to read another XML schema and analyze it. - Robert Harvey

2 Answers

1
votes

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;
    }
}
0
votes

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.