c# 如何将string转化为xml形式 再读取想要的节点

来源:百度知道 编辑:UC知道 时间:2024/07/06 17:27:28
如题!!!!!

XmlDocument doc = new XmlDocument();
doc.LoadXml("你的string");

这样就可以用xml来读取节点了
-----------------------------------
楼上的这位兄弟,不管37 21 ,狂贴代码啊

XmlDocument doc = new XmlDocument();
doc.LoadXml("你的string");

这样就可以用xml来读取节点了
-----------------------------------
楼上的这位兄弟,不管37 21 ,狂贴代码。

如果你的字符串是xml格式,可以用XmlDocument的LoadXML方法,如:
// 注:这段代码摘自MSDN,所以你要安装MSDN帮助,里面有你想要的
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
doc.LoadXml("<item><name>wrench</name></item>");

// Add a price element.
XmlElement newElem = doc.CreateElement("price");
newElem.InnerText = "10.95";
doc.DocumentElement.AppendChild(newElem);

// Save the document to a file and auto-indent the output.
XmlTextWriter writer = new XmlTextWriter("data.xml",null);
writer.Formatting = Formatting.Indented;
doc.Save