110,499
社区成员
发帖
与我相关
我的任务
分享
static void LoadXml()
{
string txt = @"<title>路由型与交换型互联网基础</title><author>程庆梅</author><price>27.00</price>
<title>计算机硬件技术基础</title><author>李继灿</author><price>25.00</price>
<title>软件质量保证与管理</title><author>朱少民</author><price>39.00</price>
<title>算法设计与分析</title><author>王红梅</author><price>23.00</price>";
string xml = "<root>" + txt + "</root>";
XElement root = XElement.Parse(xml);
foreach (var ele in root.Elements())
{//读取
Console.WriteLine(ele.Value);
}
Console.WriteLine("#######################");
root.Add(new XElement("title", "测试新增"));//写
Console.WriteLine(Regex.Replace(root.ToString(), @"[\n\r]*</?root>[\n\r]*", string.Empty));
}
static void LoadXml()
{
string txt = @"<title>路由型与交换型互联网基础</title><author>程庆梅</author><price>27.00</price>
<title>计算机硬件技术基础</title><author>李继灿</author><price>25.00</price>
<title>软件质量保证与管理</title><author>朱少民</author><price>39.00</price>
<title>算法设计与分析</title><author>王红梅</author><price>23.00</price>";
XElement root = XElement.Parse("<root>" + txt + "</root>");
foreach(var ele in root.Elements())
{
Console.WriteLine(ele.Value);
}
}