C#:反序列化XML文件错误(认为这是一个命名空间问题 – 但是我的生活不能解决它)
我正在反序列化一个XML文件,该文件来自我们的一个客户的Web服务。
问题是,在使用xsd.exe创建类之后,我将文件反序列化并获得通常的“XML文档中存在错误(2,2)”。 视觉工作室错误。 这个,我假设是第2行,它指向命名空间声明:
XML文件的顶部:
MX 2009-05-11T09:48:51+01:00 SUPPLIER 12420317323327108
顶级:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.42")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.mro.com/mx/integration")] [System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.mro.com/mx/integration", IsNullable=false)] public partial class MXWorkorderOutResp { private MXWorkorderOutRespHeader[] headerField; private MXWorkorderOutRespContentMXWORKORDERWORKORDER[][][] contentField; private string languageField; /// [System.Xml.Serialization.XmlElementAttribute("Header")] public MXWorkorderOutRespHeader[] Header { get { return this.headerField; } set { this.headerField = value; } } /// [System.Xml.Serialization.XmlArrayItemAttribute("MXWORKORDER", typeof(MXWorkorderOutRespContentMXWORKORDERWORKORDER[]), IsNullable=false)] [System.Xml.Serialization.XmlArrayItemAttribute("WORKORDER", typeof(MXWorkorderOutRespContentMXWORKORDERWORKORDER), IsNullable=false, NestingLevel=1)] public MXWorkorderOutRespContentMXWORKORDERWORKORDER[][][] Content {
我认为有一个错误:
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true, Namespace="http://www.mro.com/mx/integration")] [System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.mro.com/mx/integration", IsNullable=false)]
XML的一部分,但我不知道要改变什么 – 或者VS想要什么。
任何帮助所有赞赏的人,我仍然是这一切的新手,我的老板一直在呼吸我,让这个工作:(
编辑:有一个内在的例外是! 对不起大家!
{" was not expected."}
那么如何将这个名称空间声明添加到类中呢?
soap信封不是序列化对象的一部分。 它是SOAP传输协议的一部分。 您需要从信封中删除对象,而不是让对象处理信封。
而不是采取整个xml文件(由于某种原因,包括soap信封),你需要采取soap:body中的第一个孩子,并使用THAT反序列化到您的对象。
查看此SOpost……
使用C#和XDocument / XElement来解析Soap响应
…解决文件解析问题。
- 如何存储和检索Winforms Devexpress到MS Access数据库的RibbonGroup单选按钮和function区控件CheckBox?
- 如何使用Visual C#从SQL Server表中获取ID号
- 为什么TextRenderer.MeasureText不能在C#中使用较大的字体正确测量文本?
- 正则表达式匹配两个或多个连续字符
- 在对话框中更新设置时C#重新加载/重绘表单
- .NET-Assemblies的默认(程序集).dll.config文件有什么用?
- SSH.NET:是否可以使用SFTP上传文件并保留源文件中的文件日期?
- MongoDB c#驱动程序 – 名为Id的字段可以不是Id吗?
- 覆盖AspNet.Security.OpenIdConnect.Server中的TokenEndPoint