.net读取XML文件问题 急!急!急!

2024-12-02 11:55:33
推荐回答(3个)
回答1:

XmlDocument doc = new XmlDocument();
doc.LoadXml("xml格式字符串");
然后操作doc 你的xml数据都在doc里面

回答2:

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("加载你的XML文件");

foreach (XmlNode node in xmlDoc.SelectNodes("//CLASS_VALUE"))
{ //遍历每个CLASS_VALUE节点
string strID = node.Attributes["id"].Value;
string strName = node.Attributes["name"].Value;
}

回答3:

using System;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace RegexTest
{
public class RegexTest
{
public void Test()
{
string input = @"
-
-
-
-



-





-







-






-



-
-



-
-



-






";

string pattern = @"id="(?[^"]+)"\s*name="(?[^"]+)";
RegexOptions options = RegexOptions.None | RegexOptions.IgnoreCase | RegexOptions.Singleline;
Regex regex = new Regex(pattern, options);
MatchCollection matches = regex.Matches(input);

foreach (Match match in matches)
{
Console.WriteLine(match.Groups["id"].value + "\t" + match.Groups["name"].value );
}
}
}
}