Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 加载XML进行反序列化时自动生成DTO元素_C#_Xml_Dto - Fatal编程技术网

C# 加载XML进行反序列化时自动生成DTO元素

C# 加载XML进行反序列化时自动生成DTO元素,c#,xml,dto,C#,Xml,Dto,建议我在加载适当的XML进行反序列化时自动生成DTO元素的适当解决方案 这是我的DTO using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml.Serialization; namespace GHelper.DTO { public class ElementsDTO { [XmlRoot("GalLC")]

建议我在加载适当的XML进行反序列化时自动生成DTO元素的适当解决方案

这是我的DTO

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace GHelper.DTO
{
    public class ElementsDTO
    {
        [XmlRoot("GalLC")]
        public class FareBB
        {
            [xmlElement("Ip")]
            public string strIp { get; set; }
            [xmlElement("Port")]
            public int intPort { get; set; }
            [xmlElement("Type")]
            public int intPort{ get; set; }
            [xmlElement("Email")]
            public string strEmail{ get; set; }
        }
    }
}
这是我的XML

<GalLC>
    <Ip>192.168.2.100</Ip>
    <Port>5051</Port>
    <Type></Type>
    <Email></Email>
</GalLC>

192.168.2.100
5051
问题是:当我得到一个冗长的XML时,我将花费大量时间为它创建DTO。
请给我一些关于自动创建DTO的建议

考虑到听起来您已经解决了如何获取XML模式定义(XSD)的问题,或者有其他解决方案。。。如果您想要真正定制的东西,您可以研究一下。

您有XML模式(XSD)吗?有一些工具可以从中生成类定义。如果没有这些,任何工具都会猜测数据类型和结构是什么。所以结构也会改变,对吗?我希望你明白我正在尝试反序列化到对象中。你从XML中提取每个元素吗?除了使用序列化之外,还有很多解析XML的方法。编写解析代码的时间与编写序列化代码的时间大致相等。@SusajSNair yes。但是您不能从示例文件生成类/对象-您需要一个XML模式。它怎么知道只允许一个IP?它怎么知道
端口
是一个整数呢?感谢它部分地帮助了我..比如,创建类。对于反序列化,我应该做什么…:(从那时起,您应该能够使用。