Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#以XML格式显示_C#_Xml - Fatal编程技术网

C#以XML格式显示

C#以XML格式显示,c#,xml,C#,Xml,在执行以下操作时,我希望输出一个xml XElement Root = XElement.Load(@"d:\xmlfiles\Customers.xml"); XElement BringContact = Root.Element("Contact"); Response.Write(BringContact); 作为 我需要什么样的代码更改?这是因为浏览器将其解释为标记。在浏览器中使用“查看源”查看实际输出 您还可以通过设置内容类型明确告诉浏览器您正在返回xml: Response.

在执行以下操作时,我希望输出一个xml

XElement Root = XElement.Load(@"d:\xmlfiles\Customers.xml");
XElement BringContact = Root.Element("Contact");
Response.Write(BringContact);
作为


我需要什么样的代码更改?

这是因为浏览器将其解释为标记。在浏览器中使用“查看源”查看实际输出

您还可以通过设置内容类型明确告诉浏览器您正在返回xml:

  Response.ContentType = "text/xml";
  Response.ContentEncoding = Encoding.UTF8;

这是因为浏览器将其解释为标记。在浏览器中使用“查看源”查看实际输出

您还可以通过设置内容类型明确告诉浏览器您正在返回xml:

  Response.ContentType = "text/xml";
  Response.ContentEncoding = Encoding.UTF8;

您可以使用
HttpUtility.HtmlEncode()
获取要显示在浏览器中的括号。

您可以使用
HttpUtility.HtmlEncode()
获取要显示在浏览器中的括号

  Response.ContentType = "text/xml";
  Response.ContentEncoding = Encoding.UTF8;