当前位置:网站首页>XML入门二
XML入门二
2022-07-04 12:42:00 【华为云】
Xml基础02
几种序列化方式和反序列化:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace day29test03{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { //声明对象方式 Person person = new Person(); person.Age = 20; person.Name = "qew"; person.Height = 1777; //序列方式 基本的xml序列化 System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Person)); System.IO.TextWriter yw = new System.IO.StreamWriter(@"F:\.net学习\test\xmldeemp1\1.xml"); xmlSerializer.Serialize(yw, person); yw.Dispose(); //二进制序列化 通用性强 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //soap序列化 用于网络上传输数据 //SoapSeriailzation //输出序列化后的流 System.IO.MemoryStream ms = new System.IO.MemoryStream(); xmlSerializer.Serialize(ms, person); //缓冲过的 byte[] ns = ms.GetBuffer(); String str = System.Text.Encoding.UTF8.GetString(ns); MessageBox.Show(str); //没经过缓冲的 //byte[] vs = ms.ToArray(); } private void button2_Click(object sender, EventArgs e) { //反序列化 System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Person)); System.IO.TextReader tr = new System.IO.StreamReader(@"F:\.net学习\test\xmldeemp1\1.xml"); Person p = (Person)xmlSerializer.Deserialize(tr); //xmlSerializer.Deserialize(); } } [System.Xml.Serialization.XmlRoot("mtxml", Namespace="www.nb.com")] public class Person { private String name; private int age; private double height; public string Name { get => name; set => name = value; } public int Age { get => age; set => age = value; } public double Height { get => height; set => height = value; } }}
边栏推荐
- 数据库锁表?别慌,本文教你如何解决
- PostgreSQL 9.1 soaring Road
- Optional values and functions of the itemized contenttype parameter in the request header
- WPF double slider control and forced capture of mouse event focus
- [Android kotlin] lambda return statement and anonymous function
- Backgroundworker usage example
- 【云原生 | Kubernetes篇】深入了解Ingress(十二)
- AI painting minimalist tutorial
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
- SQL语言
猜你喜欢
三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
Database lock table? Don't panic, this article teaches you how to solve it
Master the use of auto analyze in data warehouse
高效!用虚拟用户搭建FTP工作环境
When MDK uses precompiler in header file, ifdef is invalid
6 分钟看完 BGP 协议。
实时云交互如何助力教育行业发展
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
实战:fabric 用户证书吊销操作流程
ASP.NET Core入门一
随机推荐
【云原生 | Kubernetes篇】深入了解Ingress(十二)
Golang sets the small details of goproxy proxy proxy, which is applicable to go module download timeout and Alibaba cloud image go module download timeout
Apache server access log access Log settings
七、软件包管理
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
6 分钟看完 BGP 协议。
A data person understands and deepens the domain model
再说rsync+inotify实现数据的实时备份
c#数组补充
Using nsproxy to forward messages
After installing vscode, the program runs (an include error is detected, please update the includepath, which has been solved for this translation unit (waveform curve is disabled) and (the source fil
提高MySQL深分页查询效率的三种方案
Comparative study of the gods in the twilight Era
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
2022年中国移动阅读市场年度综合分析
Annual comprehensive analysis of China's mobile reading market in 2022
敏捷开发/敏捷测试感受
Configure WebDAV server on Apache
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!