怎样获取xml中当前节点的的最后一个子节点的属性值 谢谢大家了~~最好能说说代码怎么写~~!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 XmlNode node =....你获得的当前节点string a=node.LastChild.Value;属性获取方法string b=node.LastChild.Attribte["name"].value; XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(filename); XmlNodeList topM=xmldoc.DocumentElement.ChildNodes; foreach(XmlElement element in topM) { if(element.Name=="appSettings") { XmlNodeList _node=element.ChildNodes; if(_node.Count >0) { foreach(XmlElement el in _node) { if(el.Attributes["key"].Value == "DBConnectionString") { el.Attributes["value"].Value = WebConigConnection;// string ss = @"D:\DBCustomAction.txt";// DateTime end = DateTime.Now;// StreamWriter ExecuteDmozTime = File.AppendText(ss);// ExecuteDmozTime.WriteLine("WebConigConnection:");// ExecuteDmozTime.WriteLine(end.ToString());// ExecuteDmozTime.WriteLine(WebConigConnection);// ExecuteDmozTime.WriteLine("filename:");// ExecuteDmozTime.WriteLine(filename);// ExecuteDmozTime.Flush();// ExecuteDmozTime.Close(); } } } } } xmldoc.Save(filename);楼主参考下,不过好像有个lastnote 属性,楼主可以参考参考 对应的,web.config<appSettings> <add key="day" value="0" /> <add key="hour" value="6" /> <add key="min" value="10" /></appSettings>不知道对楼主有帮助没 怎样获取xml中当前节点的的最后一个子节点的属性值 得到这个属性之后,我要把它当成一个整型的数,进行+1运算大家快点帮帮我呀~~~怎么就没人会呢? using System;using System.Collections.Generic;using System.Text;using System.IO;using System.Xml;namespace XmlNode1{ public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" + "<title>Pride And Prejudice</title>" +"<title>有点困了</title>" +"<title 无聊='相当无聊' 吃了么='没吃呢'>Pride And Prejudice</title>"+ "</book>"); XmlNode root = doc.FirstChild; //Create a new attribute. string ns = root.GetNamespaceOfPrefix("bk"); XmlNode attr = doc.CreateNode(XmlNodeType.Attribute, "genre", ns); attr.Value = "novel"; //Add the attribute to the document. root.Attributes.SetNamedItem(attr); Console.WriteLine("Display the modified XML..."); doc.Save(Console.Out); Console.ReadLine();//--------------------------------------------------- XmlNode node = doc.SelectSingleNode("book"); XmlNode lastNode = node.LastChild; XmlAttributeCollection attributes = lastNode.Attributes; foreach (XmlAttribute xa in attributes) { Console.WriteLine("属性名字: "+ xa.Name + " " +"属性值: "+ xa.Value); } Console.ReadLine();//--------------------------------------------------- } }}调试通过.自己可以修改下.其中//---------------------------------------------------中间的为寻找节点,及其最后一个子节点.并把其属性显示.自己读取建立对应的XmlDocument ,然后操作. 怎么在线程获取状态 打开窗体,并且该线程在打开窗体时候是关闭的 菜鸟求解 咋导入和导出Excel 里的数据 事件与Focus间的控制!!!!进者给分!!! C#获得IP地址的问题?(在线等!急) [winform]请大家指教一下,怎么用.net程序生成自己的.cs类文件? 请问在winform中怎么实现文字的滚动啊 请问C#有没有String.join()反函数,就是根据带某个分隔符的字符串形成一数组 烦恼啊 新手求问学C#有什么书籍能不能推荐一下,有没有那种像C++ primer plus这种经典书籍之类的 C#数据库连接的问题 vs.net2005 类关系图怎么画?
属性获取方法
string b=node.LastChild.Attribte["name"].value;
xmldoc.Load(filename); XmlNodeList topM=xmldoc.DocumentElement.ChildNodes;
foreach(XmlElement element in topM)
{
if(element.Name=="appSettings")
{
XmlNodeList _node=element.ChildNodes;
if(_node.Count >0)
{
foreach(XmlElement el in _node)
{
if(el.Attributes["key"].Value == "DBConnectionString")
{
el.Attributes["value"].Value = WebConigConnection;
// string ss = @"D:\DBCustomAction.txt";
// DateTime end = DateTime.Now;
// StreamWriter ExecuteDmozTime = File.AppendText(ss);
// ExecuteDmozTime.WriteLine("WebConigConnection:");
// ExecuteDmozTime.WriteLine(end.ToString());
// ExecuteDmozTime.WriteLine(WebConigConnection);
// ExecuteDmozTime.WriteLine("filename:");
// ExecuteDmozTime.WriteLine(filename);
// ExecuteDmozTime.Flush();
// ExecuteDmozTime.Close(); }
}
}
}
}
xmldoc.Save(filename);
楼主参考下,不过好像有个lastnote 属性,楼主可以参考参考
web.config<appSettings>
<add key="day" value="0" />
<add key="hour" value="6" />
<add key="min" value="10" />
</appSettings>
不知道对楼主有帮助没
得到这个属性之后,我要把它当成一个整型的数,进行+1运算
大家快点帮帮我呀~~~
怎么就没人会呢?
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
namespace XmlNode1
{
public class Sample
{
public static void Main()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book xmlns:bk='urn:samples' bk:ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +"<title>有点困了</title>"
+"<title 无聊='相当无聊' 吃了么='没吃呢'>Pride And Prejudice</title>"+
"</book>");
XmlNode root = doc.FirstChild;
//Create a new attribute.
string ns = root.GetNamespaceOfPrefix("bk");
XmlNode attr = doc.CreateNode(XmlNodeType.Attribute, "genre", ns);
attr.Value = "novel";
//Add the attribute to the document.
root.Attributes.SetNamedItem(attr);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
Console.ReadLine();
//---------------------------------------------------
XmlNode node = doc.SelectSingleNode("book");
XmlNode lastNode = node.LastChild;
XmlAttributeCollection attributes = lastNode.Attributes;
foreach (XmlAttribute xa in attributes)
{
Console.WriteLine("属性名字: "+ xa.Name + " " +"属性值: "+ xa.Value);
}
Console.ReadLine();
//---------------------------------------------------
}
}
}
调试通过.自己可以修改下.其中//---------------------------------------------------中间的为寻找节点,及其最后一个子节点.并把其属性显示.
自己读取建立对应的XmlDocument ,然后操作.