It will display xml in current page, but will clear all other content..
Only display a XML Document
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
XmlDocument xml = new XmlDocument();
xml.Load(Server.MapPath("products-string2.xml"));
Response.ContentType = "text/xml";
Response.Write(xml.OuterXml);
Response.End();
}
Version 2
As per your update I created the same XML from here
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
string data = string.Empty;
XElement xeRoot = new XElement("pub");
XElement xeName = new XElement("name", "Test Name");
xeRoot.Add(xeName);
XElement xeCategory = new XElement("category", "Test Category");
xeRoot.Add(xeCategory);
XDocument xDoc = new XDocument(xeRoot);
data = xDoc.ToString();
Response.ContentType = "text/xml";
Response.Write(data);
Response.End();
}
Its giving me a XML
<pub>
<name>Test Name</name>
<category>Test Category</category>
</pub>
Version 3
I don't know what you passing to the function
createXMLPub
you can also put some brakpoint to debug..
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
string data = createXMLPub(string.Empty);
Response.ContentType = "text/xml";
Response.Write(data);
Response.End();
}
public string createXMLPub(string data)
{
XElement xeRoot = new XElement("pub");
XElement xeName = new XElement("name", "Test Name");
xeRoot.Add(xeName);
XElement xeCategory = new XElement("category", "Test Category");
xeRoot.Add(xeCategory);
XDocument xDoc = new XDocument(xeRoot);
data = xDoc.ToString();
return data;
}