1 XmlDocument doc = new XmlDocument();
2 doc.Load(path);
3 string strXml = doc.InnerXml;
4 XmlNode node = doc.SelectSingleNode("data"); //data 根节点名称
5 string result = Newtonsoft.Json.JsonConvert.SerializeXmlNode(node);
6
7
8 //string pathFile = System.IO.Path.GetFullPath("../../file/josn.txt");
9 FileStream fs = new FileStream(@"../../file/josn.txt", FileMode.Create);
10
11
12 //获得字节数组
13 byte[] data = System.Text.Encoding.Default.GetBytes(result);
14 //开始写入
15 fs.Write(data, 0, data.Length);
16 //清空缓冲区、关闭流
17 fs.Flush();
18 fs.Close();