2011-03-30 67 views
0

我在db中使用了http://dotnetzip.codeplex.com/来压缩的kml文件。不幸的是我的控制器发出了URL编码的XML。何我可以阻止这一点。这里是我的代码: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); 
} 
} 

已解压的XML是这样的:

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

请用四个空格缩进代码和XML。 – SLaks 2011-03-30 15:12:49

+0

这是** XML **转义。 – SLaks 2011-03-30 15:15:57

+0

如果你不允许空值,为什么要用'int'? – SLaks 2011-03-30 15:16:34

回答

1

你提的问题是非常不清楚。
你听起来像你要求Uri.UnescapeDataString但你其实不是。


XmlTextWriter类设计用于手动构建XML。
呼号WriteStringXML -escape字符串。

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