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. 没有采用程序提供的检查方法。


你可能感兴趣的:(Web Services开发总结三 一个简单的XML格式定义)