惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
Jina AI
Jina AI
博客园_首页
J
Java Code Geeks
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 司徒正美
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
P
Proofpoint News Feed
L
Lohrmann on Cybersecurity
Forbes - Security
Forbes - Security
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
Y
Y Combinator Blog
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
N
News | PayPal Newsroom
S
Security Archives - TechRepublic
量子位
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Cisco Blogs
The Cloudflare Blog
Stack Overflow Blog
Stack Overflow Blog
L
LangChain Blog
Scott Helme
Scott Helme
S
Securelist
Security Latest
Security Latest
爱范儿
爱范儿
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
I
Intezer
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
美团技术团队
Know Your Adversary
Know Your Adversary
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
PCI Perspectives
PCI Perspectives
月光博客
月光博客
T
Tailwind CSS Blog
Cloudbric
Cloudbric
小众软件
小众软件
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
D
DataBreaches.Net
博客园 - 【当耐特】
有赞技术团队
有赞技术团队

博客园 - K3

什么是URL,URI或URN? 软件设计思想的一些文章 (持续补充中) Mac OS X 上Lua的安装方法 Objective C - 4 - 下载图片并且加载到View Objective C - 3 - 实现一个计算器 Objective C - 2 - 随机数,可变字符串,字符串,SubString Objective C - 1 - 实现一个MessageBox.Show MySQL 存储过程,游标,临时表创建 List connected users–similar to task manager How to compose namespaces? Hide/Show running Console Calculate drive total/free/available space C# list installed softwares How to: Modify a Project System So That Projects Load in Multiple Versions of Visual Studio PS:WINRAR制作32位安装程序和64位安装程序选项 使用WINRAR来制作安装程序 impersonate a user VBScript - CUD registry key and value mysql script for dynamic running sql script
XmlElement可以避免由XmlSerializer多余生成的代码
K3 · 2013-09-04 · via 博客园 - K3
public class Program
    {
        static void Main(string[] args)
        {
            var alarm = new Alarm()
            {
                Code = "1588-OPER-2",
                Grade = "1",
                Source = "55A3E6C7E2A0560A956D3933F42E5AA2",
                Time = DateTime.Now,
                Text = "Operationnal state is offline."
            };

            var alarm1 = new Alarm()
            {
                Code = "1588-OPER-2",
                Grade = "2",
                Source = "55A3E6C7E2A0560A956D3933F42E5AA2",
                Time = DateTime.Now,
                Text = "Operationnal state is offline."
            };

            var alarms = new AlarmSet("wxboss.srm.alarm", new List<Alarm> { alarm, alarm1 });


            var alarmFile = new AlarmCatalog();
            alarmFile.Alarms = new List<AlarmSet> { alarms };

            Generate(alarmFile);

        }

        public static void Generate(AlarmCatalog file)
        {
            string path = "C:\\test.xml";

            Stream stream = new FileStream(path, FileMode.Create);

            var serializer = new XmlSerializer(typeof(AlarmCatalog));
            serializer.Serialize(stream, file);

            stream.Close();
        }

        [XmlRoot("dc")]
        public class AlarmCatalog
        {
            [XmlElement("mo")]
            public List<AlarmSet> Alarms { get; set; }
        }

        public class AlarmSet
        {
            #region Initialization
            public AlarmSet()
            {

            }

            public AlarmSet(string domain)
            {
                this.Domain = domain;
            }

            public AlarmSet(string domain, List<Alarm> items)
            {
                this.Domain = domain;
                this.Items = items;
            }
            #endregion

            [XmlAttribute("dn")]
            public string Domain { get; set; }

            [XmlElement("alarm")]
            public List<Alarm> Items { get; set; }
        }

        public class Alarm
        {
            public Alarm() { }

            public Alarm(string text)
            {
                this.Text = text;
            }

            [XmlAttribute("source")]
            public string Source { get; set; }

            [XmlAttribute("grade")]
            public string Grade { get; set; }

            [XmlAttribute("code")]
            public string Code { get; set; }

            [XmlIgnore]
            public DateTime Time { get; set; }

            [XmlAttribute("time")]
            public string TimeString
            {
                get { return this.Time.ToString("yyyy-MM-dd HH:mm:ss"); }
                set { this.Time = DateTime.Parse(value); }
            }

            [XmlText]
            public string Text { get; set; }
        }
    }
<?xml version="1.0"?><dc xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><mo dn="wxboss.srm.alarm">
  <
alarm time="2013-09-04 11:33:01" code="1588-OPER-2" grade="1" source="55A3E6C7E2A0560A956D3933F42E5AA2">Operationnal state is offline.</alarm>
  <
alarm time="2013-09-04 11:33:01" code="1588-OPER-2" grade="2" source="55A3E6C7E2A0560A956D3933F42E5AA2">Operationnal state is offline.</alarm>
</
mo>

</

dc>