views:

48

answers:

2

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?

A: 

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.

Pieter
Unfortunately, I need the comments.
Robert Harvey
Seen my comment? Do you have line/position numbers of the exception?
Pieter
+1  A: 

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;
    }
}
eschneider
I did use an earlier version of XSD, so I ran it again using the version you are referencing, and did a file compare. The only differences between the two files were the CompilerGenerated attribute versions, so I didn't bother to test the new file. Weird. I'll test the new file and let you know.
Robert Harvey
I think the problem still exists (Break on all errors was off). I think the generated class is bad though...
eschneider
Yeah, it threw the same exception.
Robert Harvey