Web Services开发总结三 一个简单的XML格式定义

C# 控制台应用程序



using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace XML_Example
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<Example>" + "</Example>");
            //Get the root of doc.
            XmlNode root = doc.DocumentElement;
           
            //One person
            XmlElement e0 = doc.CreateElement("Person");
            //Set the Attribute of e0.
            e0.SetAttribute("Visable", "true");
            //Add e0 to doc through root.
            root.AppendChild(e0);

            XmlElement e1 = doc.CreateElement("Name");
            e1.InnerText = "LiLei";
            e0.AppendChild(e1);

            XmlElement e2 = doc.CreateElement("Sex");
            e2.InnerText = "Male";
            e0.AppendChild(e2);

            //Another person
            XmlElement e3 = doc.CreateElement("Person");
            e3.SetAttribute("Visable","true");
            root.AppendChild(e3);

            XmlElement e4 = doc.CreateElement("Name");
            e4.InnerText = "HanMeiMei";
            e3.AppendChild(e4);

            XmlElement e5 = doc.CreateElement("Sex");
            e5.InnerText = "Female";
            e3.AppendChild(e5);


            //Output doc to screen.
            Console.WriteLine(doc.OuterXml);


        }
    }
}

 

 

P.S.

没有实现的功能备注:

1. doc的输出不便于查看;

2. 没有采用程序提供的检查方法。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值