url编码的xml文件

时间:2011-03-30 15:09:12

标签: asp.net asp.net-mvc

我在db中使用http://dotnetzip.codeplex.com/压缩了kml文件。不幸的是,我的控制器喷出了url编码的xml。我可以防止这种情况。这是我的代码:

public void GetKMZById(int? Id)
{
try
{
    if (Id == null)
    {
    throw new ArgumentException("No Id provided.");
    }

    Response.AddHeader("Content-Disposition", "attachment;filename=Map.kmz");
    Response.AppendHeader("Connection", "close");
    Response.ContentType = "application/vnd.google-earth.kmz";
    Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
    //Response.Charset = "utf-8";
    //Response.HeaderEncoding = UnicodeEncoding.UTF8;
    //Response.ContentEncoding = UnicodeEncoding.UTF8;

    SearchKMZFile SearchKMZFile = SearchKMZFileRepository.Get((int)Id);

    ZipOutputStream outzip = new ZipOutputStream(Response.OutputStream);
    outzip.EnableZip64 = Zip64Option.Never;
    outzip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
    outzip.PutNextEntry("Map.kml");

    XmlTextWriter xmlTW = new XmlTextWriter(outzip, Encoding.UTF8);
    xmlTW.WriteString(SearchKMZFile.KMZ);

    xmlTW.Flush();
    outzip.Close();
}
catch (Exception e)
{
    ModelState.AddModelError("Exception", e.Message);
}
}

unziped xml看起来像这样:

<?xml version="1.0" encoding="us-ascii"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <Style id="s">
      <LineStyle>

1 个答案:

答案 0 :(得分:1)

你的问题很不清楚 你听起来好像要求Uri.UnescapeDataString但实际上并非如此。


XmlTextWriter类旨在手动构建XML Callign WriteString XML - 转换字符串。

如果您有一个已包含XML的字符串,则只需使用StreamWriter将文本直接写入流中。