当前位置:网站首页>Introduction to XML II
Introduction to XML II
2022-07-04 13:41:00 【Hua Weiyun】
Xml Basics 02
Several serialization methods and deserialization :
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) { // Declare object mode Person person = new Person(); person.Age = 20; person.Name = "qew"; person.Height = 1777; // Sequence mode Basic xml serialize System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Person)); System.IO.TextWriter yw = new System.IO.StreamWriter(@"F:\.net Study \test\xmldeemp1\1.xml"); xmlSerializer.Serialize(yw, person); yw.Dispose(); // Binary serialization Strong commonality System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); //soap serialize It is used to transmit data on the network //SoapSeriailzation // Output the serialized stream System.IO.MemoryStream ms = new System.IO.MemoryStream(); xmlSerializer.Serialize(ms, person); // Buffered byte[] ns = ms.GetBuffer(); String str = System.Text.Encoding.UTF8.GetString(ns); MessageBox.Show(str); // Unbuffered //byte[] vs = ms.ToArray(); } private void button2_Click(object sender, EventArgs e) { // Deserialization System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(Person)); System.IO.TextReader tr = new System.IO.StreamReader(@"F:\.net Study \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; } }}
边栏推荐
- 面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
- .NET 使用 redis
- Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
- 上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
- 8 expansion sub packages! Recbole launches 2.0!
- Talk about the design and implementation logic of payment process
- mysql三级分销代理关系存储
- 《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话
- Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
- The old-fashioned synchronized lock optimization will make it clear to you at once!
猜你喜欢
Annual comprehensive analysis of China's mobile reading market in 2022
Meituan Ali's Application Practice on multimodal recall
2022年中国移动阅读市场年度综合分析
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
N++ is not reliable
《预训练周刊》第52期:屏蔽视觉预训练、目标导向对话
爬虫练习题(一)
阿里云有奖体验:用PolarDB-X搭建一个高可用系统
eclipse链接数据库中测试SQL语句删除出现SQL语句语法错误
Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
随机推荐
Valentine's Day confession code
MySQL three-level distribution agent relationship storage
Talk about the design and implementation logic of payment process
CVPR 2022 | TransFusion:用Transformer进行3D目标检测的激光雷达-相机融合
二分查找的简单理解
Dgraph: large scale dynamic graph dataset
JVM系列——栈与堆、方法区day1-2
Simple understanding of binary search
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Node の MongoDB 安装
Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
Deploy halo blog with pagoda
A taste of node JS (V), detailed explanation of express module
Use fail2ban to prevent password attempts
从0到1建设智能灰度数据体系:以vivo游戏中心为例
Database lock table? Don't panic, this article teaches you how to solve it
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
MDK在头文件中使用预编译器时,#ifdef 无效的问题
C#基础补充
XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法