写入的xml文件为什么少个空格
我用
private string getHtml(string url)
{
try
{
WebClient myWebClient = new WebClient();
byte[] myDataBuffer = myWebClient.DownloadData(url);
return Encoding.Default.GetString(myDataBuffer);
}
catch (WebException webEx)
{
MessageBox.Show(this, webEx.Message.ToString());
return " ";
}
}
获取一网上的xml文件,然后用
StreamWriter sw = new StreamWriter( "output.xml ",false,Encoding.UTF8);
sw.Write(textBox1.Text);
sw.Close();写入output.xml文件,然后打开时老是显示错误,我用记事本打开后把 <?xml version= "1.0 " encoding= "gb2312 "?> 后面?号之间加个空格,格式就对了,这是怎么回事呢应该是getHtml写的不对巴
------解决方案--------------------先断点调试一下,看看getHtml得到的xml文件是否为空格?
------解决方案--------------------使用下面方式,以下是完整代码,
==================================
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using System.Xml.Xsl;
using System.Xml;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Net;
using System.Web;
using System.Windows.Forms;
namespace Zhzuo.VS2005Test.ConsoleTest
{
class Program
{
static void Main(string[] args)
{
string url = "http://blog.csdn.net/zhzuo/Rss.aspx ";
byte[] value = GetData(url);
using (StreamWriter sm = new StreamWriter(@ "c:\data.xml "))
{
string s = System.Text.Encoding.UTF8.GetString(value);
sm.Write(s);
}
//System.Console.ReadLine();
}
static byte[] GetData(string url)