当前位置:网站首页>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; } }}
边栏推荐
- 老掉牙的 synchronized 锁优化,一次给你讲清楚!
- 光环效应——谁说头上有光的就算英雄
- 使用Scrcpy投屏
- Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow
- Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
- PostgreSQL 9.1 飞升之路
- Reading cognitive Awakening
- 面试官:Redis 过期删除策略和内存淘汰策略有什么区别?
- Using nsproxy to forward messages
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
猜你喜欢
Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
ASP.NET Core入门一
Meituan Ali's Application Practice on multimodal recall
一文掌握数仓中auto analyze的使用
8 expansion sub packages! Recbole launches 2.0!
eclipse链接数据库中测试SQL语句删除出现SQL语句语法错误
比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
PostgreSQL 9.1 soaring Road
《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话
随机推荐
Use fail2ban to prevent password attempts
Alibaba cloud award winning experience: build a highly available system with polardb-x
SQL statement syntax error in test SQL statement deletion in eclipse linked database
Apache服务器访问日志access.log设置
室外LED屏幕防水吗?
ASP.NET Core入门一
After the game starts, you will be prompted to install HMS core. Click Cancel, and you will not be prompted to install HMS core again (initialization failure returns 907135003)
实战:fabric 用户证书吊销操作流程
一个数据人对领域模型理解与深入
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
SQL语言
When MDK uses precompiler in header file, ifdef is invalid
AI 绘画极简教程
Deploy halo blog with pagoda
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
「小技巧」给Seurat对象瘦瘦身
高效!用虚拟用户搭建FTP工作环境
光环效应——谁说头上有光的就算英雄
Using scrcpy projection