C#读取XML点滴
http://www.cnblogs.com/sopper/archive/2006/11/03/549435.html
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("root");
XmlElement companyId = doc.CreateElement("companyId");
companyId.InnerText = "1";
root.AppendChild(companyId);
doc.AppendChild(root);
string kk = doc.OuterXml;
///////////////////////////
try
{
XmlDocument doc = new XmlDocument();
XmlElement root = doc.CreateElement("root");
foreach (var item in dict)
{
XmlElement e = doc.CreateElement(item.Key);
e.InnerText = item.Value;
root.AppendChild(e);
}
doc.AppendChild(root);
return doc.OuterXml;
}
catch (Exception)
{
return "";
}
写
XDocument doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("root",
new XElement("companyId", "1")
)
);
string kk = doc.ToString();
---------
XDocument doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
XElement root = new XElement("root");
XElement element = new XElement("companyId");
element.Value = 1 + "";
root.Add(element);
doc.Add(root);
元素读取
XElement els = XElement.Parse(msg);
var companyId = from e in els.Elements("companyId")
select e;
string kk = companyId.First().Value;
posted on 2009-07-30 10:11
黄小二 阅读(270)
评论(0) 编辑 收藏 所属分类:
ASP.NET 、
C#