ASP.NET读取XML 如何运用 root.SelectNodes 找不到节点 楼主你应该把xml用文字的形式发送上来,那样的话大家猜可以拷贝你的xml中的内容来帮你完成你的程序。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class XmlProvider : IDisposable { private string a; private XmlDocument b; public XmlProvider(string XmlFile) { try { this.b = new XmlDocument(); this.b.Load(XmlFile); } catch { } this.a = XmlFile; } public void DeleteNode(string NodeName) { string xpath = NodeName.Substring(0, NodeName.LastIndexOf("/")); this.b.SelectSingleNode(xpath).RemoveChild(this.b.SelectSingleNode(NodeName)); } public void Dispose() { this.Dispose(true); } protected void Dispose(bool Diposing) { this.b = null; } public void InsertElement(string mainNode, string element, string content) { XmlNode node = this.b.SelectSingleNode(mainNode); XmlElement newChild = this.b.CreateElement(element); newChild.InnerText = content; node.AppendChild(newChild); } public void InsertElement(string mainNode, string element, string attrib, string attribContent, string content) { XmlNode node = this.b.SelectSingleNode(mainNode); XmlElement newChild = this.b.CreateElement(element); newChild.SetAttribute(attrib, attribContent); newChild.InnerText = content; node.AppendChild(newChild); } public void InsertNode(string mainNode, string childNode, string element, string content) { XmlNode node = this.b.SelectSingleNode(mainNode); XmlElement newChild = this.b.CreateElement(childNode); node.AppendChild(newChild); XmlElement element3 = this.b.CreateElement(element); element3.InnerText = content; newChild.AppendChild(element3); } public string ReadAttribute(string PathNode, string AttributeName) { string str = ""; try { str = this.b.SelectSingleNode(PathNode).Attributes[AttributeName].Value; } catch { Responses.Write(PathNode); Responses.End(); } return str; } public string ReadInnerText(string PathNode) { return this.b.SelectSingleNode(PathNode).InnerText; } public XmlNode ReadNode(string PathNode) { return this.b.SelectSingleNode(PathNode); } public void Save() { try { this.b.Save(this.a); } catch { } this.b = null; } public void UpdateAttribute(string PathNode, string AttributeName, int AttributeValue) { this.b.SelectSingleNode(PathNode).Attributes[AttributeName].Value = AttributeValue.ToString(); } public void UpdateAttribute(string PathNode, string AttributeName, string AttributeValue) { this.b.SelectSingleNode(PathNode).Attributes[AttributeName].Value = AttributeValue; } public void UpdateInnerText(string PathNode, string InnerText) { this.b.SelectSingleNode(PathNode).InnerText = InnerText; } } xml文件内容太多了就折叠出来了 如何编写搜索按钮和显示结果页面的代码C# 请教论文的选题(asp.net) 请教各位:当双引号、单引号嵌套使用时不够用该怎么办? AjaxPro如何做到局部的更新DATALIST? **所有分请教简单问题** DropDownList在绑定情况下怎么给第一行设置为Null 怎样让imagebutton在新窗体中打开页面? 一个很简单的问题,请过客停留一下 急——关于datagrid中的按钮问题 请教一个关于dataview的问题 主页更新 微软发布的Oxite开源博客平台配置? 急求AspNetPager分页控件结合存储过程分页问题
{
private string a;
private XmlDocument b; public XmlProvider(string XmlFile)
{
try
{
this.b = new XmlDocument();
this.b.Load(XmlFile);
}
catch
{
}
this.a = XmlFile;
} public void DeleteNode(string NodeName)
{
string xpath = NodeName.Substring(0, NodeName.LastIndexOf("/"));
this.b.SelectSingleNode(xpath).RemoveChild(this.b.SelectSingleNode(NodeName));
} public void Dispose()
{
this.Dispose(true);
} protected void Dispose(bool Diposing)
{
this.b = null;
} public void InsertElement(string mainNode, string element, string content)
{
XmlNode node = this.b.SelectSingleNode(mainNode);
XmlElement newChild = this.b.CreateElement(element);
newChild.InnerText = content;
node.AppendChild(newChild);
} public void InsertElement(string mainNode, string element, string attrib, string attribContent, string content)
{
XmlNode node = this.b.SelectSingleNode(mainNode);
XmlElement newChild = this.b.CreateElement(element);
newChild.SetAttribute(attrib, attribContent);
newChild.InnerText = content;
node.AppendChild(newChild);
} public void InsertNode(string mainNode, string childNode, string element, string content)
{
XmlNode node = this.b.SelectSingleNode(mainNode);
XmlElement newChild = this.b.CreateElement(childNode);
node.AppendChild(newChild);
XmlElement element3 = this.b.CreateElement(element);
element3.InnerText = content;
newChild.AppendChild(element3);
} public string ReadAttribute(string PathNode, string AttributeName)
{
string str = "";
try
{
str = this.b.SelectSingleNode(PathNode).Attributes[AttributeName].Value;
}
catch
{
Responses.Write(PathNode);
Responses.End();
}
return str;
} public string ReadInnerText(string PathNode)
{
return this.b.SelectSingleNode(PathNode).InnerText;
} public XmlNode ReadNode(string PathNode)
{
return this.b.SelectSingleNode(PathNode);
} public void Save()
{
try
{
this.b.Save(this.a);
}
catch
{
}
this.b = null;
} public void UpdateAttribute(string PathNode, string AttributeName, int AttributeValue)
{
this.b.SelectSingleNode(PathNode).Attributes[AttributeName].Value = AttributeValue.ToString();
} public void UpdateAttribute(string PathNode, string AttributeName, string AttributeValue)
{
this.b.SelectSingleNode(PathNode).Attributes[AttributeName].Value = AttributeValue;
} public void UpdateInnerText(string PathNode, string InnerText)
{
this.b.SelectSingleNode(PathNode).InnerText = InnerText;
}
}
就折叠出来了