加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XML使用c#从xsd反序列化iso 20022 pain.001.001.03

发布时间:2020-12-16 23:03:41 所属栏目:百科 来源:网络整理
导读:我想从xml文件中获取一个对象.在我的例子中,我使用iso 2002 pain.001.001.03 我已经从中下载了架构 pain.001.001.03.xsd 和来自的xml文件 pain.001.001.03.xml 我已使用此工具对xsd验证了我的xml Validate XML 我使用xsd生成了一个类 我正在使用下面的代码来
我想从xml文件中获取一个对象.在我的例子中,我使用iso 2002 pain.001.001.03

ISO 200022 pain.001.001.03

我已经从中下载了架构

pain.001.001.03.xsd

和来自的xml文件

pain.001.001.03.xml

我已使用此工具对xsd验证了我的xml

Validate XML

我使用xsd生成了一个类

enter image description here

我正在使用下面的代码来反序列化

XmlSerializer ser = new XmlSerializer(typeof(CustomerCreditTransferInitiationV03),new XmlRootAttribute                             
                     { 
                         ElementName = "Document",Namespace = "urn:iso:std:iso:20022:tech:xsd:pain.001.001.03",});


           FileStream myFileStream = new FileStream("C:01.001.03pain.001.001.03.xml",FileMode.Open);

           CustomerCreditTransferInitiationV03 myObject = (CustomerCreditTransferInitiationV03) ser.Deserialize(myFileStream);

代码返回null值,但我的xml有值

enter image description here

解决方法

<?xml version="1.0" encoding="UTF-8"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:iso:std:iso:20022:tech:xsd:pain.001.001.03">
    <CstmrCdtTrfInitn>

根元素是Document,而不是CstmrCdtTrfInitn:

var serializer = new XmlSerializer(typeof(Document));
using (var file = File.OpenRead(path))
{
    var document = (Document)serializer.Deserialize(file);
    var transfer = document.CstmrCdtTrfInitn;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读