I am working on an app that needs to call and aspx page and that page needs to return raw xml data/text.
So calling on xmldata.aspx would return a DB dump in raw text xml.
This is the code so far, but I do not know how to make the xml return as pure xml, not xml text dumped into and html page. Something to do with setting the page encoding?
here is my code so far:
Code:
private void Page_Load(object sender, System.EventArgs e)
{
String strConnect;
String strCommand;
strConnect = @"Data Source=DEV;Initial Catalog=CORP;Persist Security Info=True;Packet Size=4096";
strCommand = "SELECT TOP 5 * FROM ARTICLE WHERE ARTICLE_LANGUAGE='EN'";
SqlConnection myConnection_Groups = new SqlConnection(strConnect);
SqlCommand myCommand_Groups = new SqlCommand(strCommand,myConnection_Groups);
myConnection_Groups.Open();
SqlDataReader myReader_Groups;
myReader_Groups = myCommand_Groups.ExecuteReader();
// XML Document Startup before Loop
XmlDocument xmlDoc = new XmlDocument();
XmlDeclaration declarer = xmlDoc.CreateXmlDeclaration("1.0","UTF-8","yes");
xmlDoc.AppendChild(declarer);
// Root Structure
XmlElement article_list = xmlDoc.CreateElement("article_list");
XmlElement article, title,description,body;
XmlText textNode;
while (myReader_Groups.Read())
{
//Add an Article to the XML
article = xmlDoc.CreateElement("article");
article.SetAttribute("id", myReader_Groups["ARTICLE_ID"].ToString());
article.SetAttribute("title_colour","#FFFFFF");
article.SetAttribute("language",myReader_Groups["ARTICLE_LANGUAGE"].ToString());
article.SetAttribute("image","Car.jpg");
article_list.AppendChild(article);
title = xmlDoc.CreateElement("title");
description = xmlDoc.CreateElement("description");
body = xmlDoc.CreateElement("body");
textNode = xmlDoc.CreateTextNode("titletext");
textNode.Value = myReader_Groups["ARTICLE_TITLE"].ToString();
article.AppendChild(title);
title.AppendChild(textNode);
textNode = xmlDoc.CreateTextNode("descriptiontext");
textNode.Value = myReader_Groups["ARTICLE_DESCRIPTION"].ToString();
article.AppendChild(description);
description.AppendChild(textNode);
}
// always call Close when done reading.
myReader_Groups.Close();
// Close the connection when done with it.
myReader_Groups.Close();
//Dump XML to the Text box
xmldata.Text=article_list.OuterXml;
}
I am dumping the xml output for now into a textbox to debug the output. I noticed the output is ok, but I dont see the preamble showing up either <?xml version="1.0" ?>..
anyone have any suggestions on how to dump only an XML chunk as opposed to a aspx html with xml inside it.