Мой корневой класс элемента выглядит так:
Код: Выделить всё
[System.ComponentModel.DescriptionAttribute("This is the root object of the XML data. It defines the entire DF")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.0.662.0")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute("dfType", Namespace="http://www.company.org/a661")]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlRootAttribute("a661_df", Namespace="http://www.company.org/a661")]
public partial class DfType : ElementType
{
...
[System.ComponentModel.DataAnnotations.RequiredAttribute()]
[System.Xml.Serialization.XmlElementAttribute("a661_layer")]
public System.Collections.ObjectModel.Collection A661_Layer
{
...
Код: Выделить всё
private DFApiGenerator.Xml.DfType LoadDefinitionFile(string path)
{
// Read df as text
string df = File.ReadAllText(path);
// Dump bytes of patched df file
byte[] dfBytes = Encoding.ASCII.GetBytes(df);
// Deserialize
// Load input file
using MemoryStream memoryStream = new MemoryStream(dfBytes);
// Create Reader
XmlReader xmlReader = new XmlTextReader(memoryStream);
XmlRootAttribute rootAttribute = new XmlRootAttribute("a661_df");
rootAttribute.Namespace = ""; // in order to support the case where xmlns is not set
// Load xml Model
XmlSerializer serializer = new XmlSerializer(typeof(DFApiGenerator.Xml.DfType), rootAttribute);
// Deserialization
return (DFApiGenerator.Xml.DfType)serializer.Deserialize(xmlReader);
}
Действительно, у меня есть исключение NoSuchElementException, когда код:
Код: Выделить всё
DfType.A661_Layer.First()
Вот фрагмент XML-файла, который я пытаюсь десериализовать:
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-xmlns-se
Мобильная версия