可扩展标识语言XML

自己定义节点

<?xml version="1.0" encoding="UTF-8"?>

<message>

<note>

<to>Tove</to>

<from>Jani</from>

<heading>Reminder</heading>

<body>Don't forget me this weekend!</body>

</note>

</message>

程序示例

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Collections;

using System.Xml;

 
 

namespace ConsoleApplication9

{

class
Program

{

static
void Main(string[] args)

{

XmlDocument xml = new
XmlDocument();

xml.Load(@"C:\Users\xudajun\Desktop\test\message.xml");

XmlElement xmlroot = xml.DocumentElement;

foreach( XmlNode node in xmlroot.ChildNodes )

{

foreach(XmlNode list in node.ChildNodes)

{

switch(list.Name)

{

case
"to":

Console.WriteLine(list.InnerText);

break;

case
"from":

Console.WriteLine(list.InnerText);

break;

case
"heading":

Console.WriteLine(list.InnerText);

break;

case
"body":

Console.WriteLine(list.InnerText);

break;

 
 

}

}

}

}

}

}

执行结果


2021年8月15日

  

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注