用vs2012的命令利用xsd文件生成对应的C#类,把xml的string类型映射到生成的类

时间:2022-04-29 11:55:50

用vs2012的命令利用xsd文件生成对应的C#类,把xml的string类型映射到生成的类

输入命令:

用vs2012的命令利用xsd文件生成对应的C#类,把xml的string类型映射到生成的类

xsd d:\TDDOWNLOAD\atom-author-link.xsd /c /language:C# /outputdir:d:\

含义:

将d:\TDDOWNLOAD\atom-author-link.xsd 架构 生成类 语言为C# 输出目录是d:\

 

把xml映射到生成的C#类:

        [XmlSerializerFormat]
        public LocHubOrder XMLMapOrder(string xml)
        {
            byte[] array = Encoding.ASCII.GetBytes(xml);
            LocHubOrder LHOrder;
            using (MemoryStream stream = new MemoryStream(array))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(LocHubOrder));
                stream.Seek(0, SeekOrigin.Begin);
                LHOrder = serializer.Deserialize(stream) as LocHubOrder;
            }
           return LHOrder;
        }