当前位置:网站首页>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; } }}
边栏推荐
- 强化学习-学习笔记1 | 基础概念
- Reading cognitive Awakening
- XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法
- "Tips" to slim down Seurat objects
- 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 soaring Road
- Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
- It is six orders of magnitude faster than the quantum chemical method. An adiabatic artificial neural network method based on adiabatic state can accelerate the simulation of dual nitrogen benzene der
- 使用宝塔部署halo博客
- 一个数据人对领域模型理解与深入
猜你喜欢
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
聊聊支付流程的设计与实现逻辑
Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
A data person understands and deepens the domain model
干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
A taste of node JS (V), detailed explanation of express module
[Android kotlin] lambda return statement and anonymous function
SQL statement syntax error in test SQL statement deletion in eclipse linked database
N++ is not reliable
随机推荐
游戏启动后提示安装HMS Core,点击取消,未再次提示安装HMS Core(初始化失败返回907135003)
XILINX/system-controller-c/BoardUI/无法连接开发板,任意操作后卡死的解决办法
Apache服务器访问日志access.log设置
Comprehensive evaluation of modular note taking software: craft, notation, flowus
Using nsproxy to forward messages
iptables基础及Samba配置举例
A taste of node JS (V), detailed explanation of express module
go-zero微服务实战系列(九、极致优化秒杀性能)
Read the BGP agreement in 6 minutes.
Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
Dry goods sorting! How about the development trend of ERP in the manufacturing industry? It's enough to read this article
Excuse me, have you encountered this situation? CDC 1.4 cannot use timestamp when connecting to MySQL 5.7
敏捷开发/敏捷测试感受
一文掌握数仓中auto analyze的使用
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
mysql三级分销代理关系存储
Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?
CTF competition problem solution STM32 reverse introduction
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
[FAQ] summary of common causes and solutions of Huawei account service error 907135701