111,116
社区成员




<webSiteList>
<site>
<siteName>雅虎网站</siteName>
<itemlist>网址</itemlist>
<itemlist>网站介绍</itemlist>
</site>
<site>
<siteName>网易网站</siteName>
<itemlist>网址</itemlist>
<itemlist>网站介绍</itemlist>
<itemlist>其他信息</itemlist>
</site>
</webSiteList>
string[] ChildNodess = SiteChildNodeStr.Split(new char[] { '\r' });
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strXmlPath);
XmlNode node = xmlDoc.SelectSingleNode("/webSiteList/site[siteName='" + SiteNameNodeStr + "']");
node["siteName"].InnerText = ModifySiteNameStr;
for (int i = 0; i < ChildNodess.Length; i++)
{
node["itemlist"].InnerText = ChildNodess[i].ToString().Replace("\r","").Replace("\n","");
}
string[] ChildNodess = SiteChildNodeStr.Split(new char[] { '\r' });
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strXmlPath);
XmlNode node = xmlDoc.SelectSingleNode("/webSiteList/site[siteName='" + SiteNameNodeStr + "']");
node["siteName"].InnerText = ModifySiteNameStr;
for (int i = 0; i < ChildNodess.Length; i++)
{
node.ChildNodes[i+1].InnerText = ChildNodess[i].ToString().Replace("\r","").Replace("\n","");
}
xmlDoc.Save(strXmlPath);
string xmlFile = Application.StartupPath + @"\a.XML";
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlNode root = doc.DocumentElement;
foreach (XmlNode node in root.ChildNodes)
{
if (node.LocalName.Equals("site"))
{
if (node.FirstChild.InnerText == "雅虎网站")
{
foreach (XmlNode childnode in node.ChildNodes)
{
if (childnode.Name == "itemlist")
{
childnode.InnerText = childnode.InnerText + "aaa";
}
}
}
}
}
StreamWriter sw = new StreamWriter(xmlFile, false, Encoding.GetEncoding("UTF-8"));
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
doc.Save(xw);
sw.Close();
string xmlFile = Application.StartupPath + @"\a.XML";
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlNode root = doc.DocumentElement;
foreach (XmlNode node in root.ChildNodes)
{
if (node.LocalName.Equals("site"))
{
if (node.FirstChild.InnerText == "雅虎网站")
{
foreach (XmlNode childnode in node.ChildNodes)
{
if (childnode.InnerText != "雅虎网站")
{
childnode.InnerText = childnode.InnerText + "aaa";
}
}
}
}
}
StreamWriter sw = new StreamWriter(xmlFile, false, Encoding.GetEncoding("UTF-8"));
XmlTextWriter xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
doc.Save(xw);
sw.Close();
string[] ChildNodess = SiteChildNodeStr.Split(new char[] { '\r' });
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strXmlPath);
XmlNode node = xmlDoc.SelectSingleNode("/webSiteList/site[siteName='" + SiteNameNodeStr + "']");
node["siteName"].InnerText = ModifySiteNameStr;
for (int i = 0; i < ChildNodess.Length; i++)
{
node.childNodes[i].InnerText = "test";
}
xmlDoc.Save(strXmlPath);
//xml查询带命名空间
XmlDocument doc = new XmlDocument();
doc.Load("C:\\nso.xml");
NameTable xmt = new NameTable();
XmlNamespaceManager xnm = new XmlNamespaceManager(xmt);
xnm.AddNamespace("ns0", "http://blog.csdn.net/zhzuo");
XmlNode node = doc.SelectSingleNode("//ns0:NewDataSet/ns0:Table1", xnm);
//如果是默认命名空间,可以添加别名进行查询。
XmlDocument doc = new XmlDocument();
doc.Load("C:\\m.xml");
NameTable xmt = new NameTable();
XmlNamespaceManager xnm = new XmlNamespaceManager(xmt);
//默认命名空间添加nn别名。
xnm.AddNamespace("ns0", "http://blog.csdn.net/zhzuo");
XmlNode node = doc.SelectSingleNode("//ns0:NewDataSet/ns0:Table1", xnm);
using System;
using System.IO;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Collections;
using System.Data;
using System.Xml;
using System.Management;
using System.Net;
namespace Zhzuo
{
class ZZConsole
{
[STAThread]
static void Main(string[] args)
{
string strXml="<?xml version=\"1.0\"?>"
+"<Data>"
+"<Head>"
+"<Nodeid>1111</Nodeid>"
+"<Subid>2222</Subid>"
+"<Version>2004</Version>"
+"<Date>20040302</Date>"
+"<Time>101500</Time>"
+"</Head>"
+"<Body>"
+"<Code>01</Code>"
+"<Name>深圳</Name>"
+"<IdType>0</IdType>"
+"<Idno>110258740824082</Idno>"
+"</Body>"
+"</Data>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(strXml);
string vv;
XmlNodeList myNodes = doc.GetElementsByTagName("Version");
vv = myNodes[0].InnerText;
//修改
myNodes[0].InnerText = "123455";
Console.WriteLine(vv);
myNodes = doc.SelectNodes("//Version");
vv = myNodes[0].InnerText;
Console.WriteLine(vv);
//修改
myNodes[0].InnerText = "67890";
doc.Save("d:\\text.xml");
Console.ReadLine();
}
}
}
xmlDoc.Save(strXmlPath);