regardé un tutoriel mais n'a pas pu obtenir ce travail:générer un XML-fichier et l'afficher dans le format XML
default.aspx:
<%@ Page Language="C#" ContentType="text/xml" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="rssPubba.Default" %>
default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";
Response.ContentEncoding = Encoding.UTF8;
XmlDocument doc = new XmlDocument();
// XML declaration
XmlNode declaration = doc.CreateNode(XmlNodeType.XmlDeclaration, null, null);
doc.AppendChild(declaration);
// Root element: article
XmlElement root = doc.CreateElement("article");
doc.AppendChild(root);
// Sub-element: author
XmlElement author = doc.CreateElement("author");
author.InnerText = "Faisal Khan";
root.AppendChild(author);
// Attribute: isadmin
XmlAttribute isadmin = doc.CreateAttribute("isadmin");
isadmin.Value = "true";
author.Attributes.Append(isadmin);
// Sub-element: title
XmlElement title = doc.CreateElement("title");
title.InnerText = "Sample XML Document";
root.AppendChild(title);
// Sub-element: body (CDATA)
XmlElement body = doc.CreateElement("body");
XmlNode cdata = doc.CreateCDataSection("This is the body of the article.");
body.AppendChild(cdata);
root.AppendChild(body);
doc.Save(Response.OutputStream);
}
mais lorsque je tente d'afficher le navigateur semble interpréter comme balisage:
sortie:
<article>
<author isadmin="true">Faisal Khan</author>
<title>Sample XML Document</title>
<body><![CDATA[This is the body of the article.]]></body>
</article>
Quels changements dois-je apporter?
J'utilise maintenant LINQ en XML, Response.End(); et un fichier ashx et ça marche! Merci – Mikael
Est-il possible d'utiliser Request. "String city = Request.QueryString [" city "];" à l'intérieur d'ashx? – Mikael