Ich habe folgende XML-Struktur (vereinfacht)
XML-Daten
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| <applications xmlns="NamespaceA" xmlns:sh="NamespaceB"> <application id="ApplicationId">
<sh:task id="TaskId"> ... </sh:task>
<category id="CategoryId"> <sh:task idref="TaskId" /> </category>
</application> </applications> |
Dies ist vorgegeben und kann bzw. darf von mir nicht verändert werden, da es sonst nicht mehr funktioniert. Mein Problem ist die markierte Zeile. Der Serializer hat offensichtlich ein Problem damit, dass der "task"-Knoten erneut auftaucht. Hier mal meine Klassen in Kurzfassung:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54:
| [XmlRoot("applications")] public class TaskApplicationFile { Collection<TaskApplication> taskApplications = new Collection<TaskApplication>();
[XmlElement("application")] public Collection<TaskApplication> TaskApplication { get { return this.taskApplications; } set { this.taskApplications = value; } } }
public class TaskApplication { Collection<TaskApplicationTask> tasks = new Collection<TaskApplicationTask>(); Collection<TaskApplicationCategoryLink> categories = new Collection<TaskApplicationCategoryLink>();
[XmlElement(ElementName = "task", Namespace = "NamespaceB", IsNullable = false)] public Collection<TaskApplicationTask> Tasks { get { return this.tasks; } set { this.tasks = value; } }
[XmlElement(ElementName = "category", IsNullable = false)] public Collection<TaskApplicationCategoryLink> Categories { get { return this.categories; } set { this.categories = value; } } }
public class TaskApplicationTask { }
public class TaskApplicationCategoryLink { Collection<TaskApplicationCategoryTaskReference> taskReference = new Collection<TaskApplicationCategoryTaskReference>();
[XmlElement(ElementName = "task", Namespace = "NamespaceB")] public Collection<TaskApplicationCategoryTaskReference> TaskReference { get { return this.taskReference; } set { this.taskReference = value; } } }
public class TaskApplicationCategoryTaskReference { } |
Es erscheint die Fehlermeldung
Zitat: |
The top XML element 'task' from namespace 'NamespaceB' references distinct types TestApp.TaskApplicationTask and TestApp.TaskApplicationCategoryTaskReference. Use XML attributes to specify another XML name or namespace for the element or types. |
Es funktioniert zwar, wenn ich den Knotennamen oder den Namespace ändere, aber genau das kann und darf ich nicht machen. Der Knoten muss zwingend "task" heißen, und auch der Namespace ist vorgegeben.
Hat jemand eine Idee, wie ich das lösen kann?