How to post XML in to asp.net page
Hello , Every one
any one can tell me how to post data form XMl to Asp.net page, and how to get out put.
its needful
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Feb 11, 2009, 10:32 AM EST
How do you want to see this data? as an XML or want to see in Grid?
Thanks
Vijaya Kadiyala
http
://dotnetvj.blogspot.comBechir BejaouiRank #144 · 15.9K reputationPosted Feb 11, 2009, 11:34 AM EST
I. The classical way
you can use xsl file to transofrm your xml file to a given html form
using System.IO;
using System.Xml.Xsl;
void TransformFroXmlToHtml() {
XslTransform oTransform = new XslTransform();
// load your already prepared XSL stylesheet.
transform.Load("
%yourpath%\yourFile.xslt");
/* Transform the xml file into html file using the xslt file. */
oTransform.Transform("%yourpath%\yourFile.xml", "%yourpath%\yourFile.html", null);}
}
Or the new way using xlinq:
of corse you add a reference to the Sytem.Xml.linq namespace
You refer your xml document as follow
var yourFileName = XElement.load(thXmlpathhere);
and you compose your request from the xml file
var request = from theNodeName in yourFileName.Elements()
select new
{
attribute1 = NodeName.attribute1
attribute2 = NodeName.attribute2
attributeN = NodeName.attributeN
}
Of Corse you have to create a class before to repesent the object whithin your xml file
for example
you have to create a class
public class car
{
public string name{get;set;}
public string power{get;set;}
public string consume{get;set}
public string speed{get;set;}
}
then you can
var request = from car in yourFileName.Elements()
select new
{
name = car.name;
power = car.power;
consume = car.consume;
speed = car.speed
}
Then you can represent this in html form
var titles = new []{
new XElement("th", "name")
new XElement("th", "power")
new XElement("th","consume")
new XElement("th",speed)
};
var body = new []{
new XElement("td", car.name)
new XElement("td", car.power)
new XElement("td",car.consume)
new XElement("td",car.speed)
};
var table = new XElement("table", titles, body);
Response.Write(table);