I'm trying to generate dynamic xml file in the code and download it. this is the function i used to it
xmlUrl Url = new xmlUrl();
Url.Url = fileName.Text;
List<xmlUrl> Urls = new List<xmlUrl>();
Urls.Add(Url);
XmlSerializer ser = new XmlSerializer(Urls.GetType());
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
ser.Serialize(writer, Urls);
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
doc.WriteTo(xmlWriter);
xmlWriter.Flush();
xmlWriter.Close();
byte[] byteArray = stream.ToArray();
Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment; filename=" + lblFile.Text + ".xml");
Response.AppendHeader("Content-Length", byteArray.Length.ToString());
Response.ContentType = "text/xml";
Response.BinaryWrite(byteArray);
this function is working. but when the xml file downloaded it contain the html code of the relevent page.
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfXmlUrl xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xmlUrl>
<Url>
Url of the web content
</Url>
</xmlUrl>
</ArrayOfXmlUrl>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta charset="utf-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
source of the body
</body>
there for i cannot parse this file with xml parse. its giving me this error.
An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
Additional information: There is no Unicode byte order mark. Cannot switch to Unicode.
how do i fix this?