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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bechir BejaouiPosted Feb 11, 2009, 4:34 PM
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);
Vijaya KadiyalaPosted Feb 11, 2009, 3:32 PM
How do you want to see this data? as an XML or want to see in Grid?
Thanks
Vijaya Kadiyala
http
://dotnetvj.blogspot.com