我使用xsd.exe
生成了类,并且获得了40多个类:
链接:https://www.pastiebin.com/5cc3253981ff6
现在我只想反序列化广告 那是我的反序列化器:
XmlSerializer serializer = new XmlSerializer(typeof(Adres));
using (StringReader reader = new StringReader(xmlDocumentText))
{
Adres info = (Adres)(serializer.Deserialize(reader));
}
但是我遇到了错误There is an error in XML document (1, 40)
下面只是XML的一部分(整个占用15MB):
答案 0 :(得分:0)
您的代码应如下所示
XmlSerializer serializer = new XmlSerializer(typeof(DomainClass.wpisyWpis));
using (StringReader reader = new StringReader(xmlDocumentText))
{
DomainClass.wpisyWpis info = (DomainClass.wpisyWpis)(serializer.Deserialize(reader));
}
您还需要在此类上方添加XmlRoot:
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[XmlRoot("wpis")]
public partial class wpisyWpis
{
private Dokument dokumentField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Namespace = "http://asseco.pl/xml/rpm/ksiegaPraktyka/2011/04/08/")]
public Dokument Dokument
{
get
{
return this.dokumentField;
}
set
{
this.dokumentField = value;
}
}
}