当前位置:网站首页>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; } }}
边栏推荐
- 7、 Software package management
- Apache服务器访问日志access.log设置
- A data person understands and deepens the domain model
- Rsyslog配置及使用教程
- Definition of cognition
- Personalized online cloud database hybrid optimization system | SIGMOD 2022 selected papers interpretation
- Comprehensive evaluation of modular note taking software: craft, notation, flowus
- Is the outdoor LED screen waterproof?
- HAProxy高可用解决方案
- A taste of node JS (V), detailed explanation of express module
猜你喜欢
Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements
C#/VB.NET 给PDF文档添加文本/图像水印
【AI系统前沿动态第40期】Hinton:我的深度学习生涯与研究心法;Google辟谣放弃TensorFlow;封神框架正式开源
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
Oracle 被 Ventana Research 评为数字创新奖总冠军
Dry goods sorting! How about the development trend of ERP in the manufacturing industry? It's enough to read this article
比量子化学方法快六个数量级,一种基于绝热状态的绝热人工神经网络方法,可加速对偶氮苯衍生物及此类分子的模拟
Practice: fabric user certificate revocation operation process
Talk about the design and implementation logic of payment process
8 expansion sub packages! Recbole launches 2.0!
随机推荐
CA: efficient coordinate attention mechanism for mobile terminals | CVPR 2021
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
在 Apache 上配置 WebDAV 服务器
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
When MDK uses precompiler in header file, ifdef is invalid
MDK在头文件中使用预编译器时,#ifdef 无效的问题
高效!用虚拟用户搭建FTP工作环境
Oracle 被 Ventana Research 评为数字创新奖总冠军
n++也不靠谱
Deploy halo blog with pagoda
爬虫练习题(一)
Annual comprehensive analysis of China's mobile reading market in 2022
Detailed explanation of mt4api documentary and foreign exchange API documentary interfaces
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
In 2022, it will be es2022 soon. Do you only know the new features of ES6?
DGraph: 大规模动态图数据集
Read the BGP agreement in 6 minutes.
Rsyslog configuration and use tutorial
Scrapy 框架学习
Meituan Ali's Application Practice on multimodal recall