当前位置:网站首页>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; } }}边栏推荐
- eclipse链接数据库中测试SQL语句删除出现SQL语句语法错误
- Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
- 干货整理!ERP在制造业的发展趋势如何,看这一篇就够了
- 在 Apache 上配置 WebDAV 服务器
- 爬虫练习题(一)
- 面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
- 8 expansion sub packages! Recbole launches 2.0!
- 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)
- n++也不靠谱
- 老掉牙的 synchronized 锁优化,一次给你讲清楚!
猜你喜欢

求解:在oracle中如何用一条语句用delete删除两个表中jack的信息

Interviewer: what is the difference between redis expiration deletion strategy and memory obsolescence strategy?

Meituan Ali's Application Practice on multimodal recall

Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example

爬虫练习题(一)

Zhongang Mining: in order to ensure sufficient supply of fluorite, it is imperative to open source and save flow

runc hang 导致 Kubernetes 节点 NotReady
提高MySQL深分页查询效率的三种方案

ArcGIS uses grid processing tools for image clipping

CANN算子:利用迭代器高效实现Tensor数据切割分块处理
随机推荐
ASP.NET Core入门一
Flet教程之 03 FilledButton基础入门(教程含源码)(教程含源码)
Can Console. Clear be used to only clear a line instead of whole console?
n++也不靠谱
AI painting minimalist tutorial
在 Apache 上配置 WebDAV 服务器
7 月数据库排行榜:MongoDB 和 Oracle 分数下降最多
7、 Software package management
Database lock table? Don't panic, this article teaches you how to solve it
面向个性化需求的在线云数据库混合调优系统 | SIGMOD 2022入选论文解读
Apache server access log access Log settings
七、软件包管理
Master the use of auto analyze in data warehouse
使用宝塔部署halo博客
Talk about the design and implementation logic of payment process
MySQL three-level distribution agent relationship storage
ISO 27001 Information Security Management System Certification
AI painting minimalist tutorial
Iptables foundation and Samba configuration examples
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!