日期:2014-05-16  浏览次数:21056 次

将URL转化成XML格式并保存问题
我想用C#将一个URL链接转换成XML格式并且保存到本地的一个文件夹里面,请问大家有什么好方法吗?
          谢谢大家的帮忙!
------解决方案--------------------

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace test写入XML
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            func();
        }

        public void func()
        {
            string jsonString = "{\"url\":\"http://www.baidu.com\"}";
            //json 的字符串需要按照这个格式 书写,否则会报错
            string json = @"{""?xml"": {""@version"": ""1.0"",""@standalone"": ""no"" },""root"":" + jsonString + "}";
            if (!string.IsNullOrEmpty(json))
            {
                XmlDocument doc = JsonConvert.DeserializeXmlNode(json);
                doc.Save("aaa.xml");
            }
        }
    }
}


實測可以用