Hi every one,
am newly enter in xml, i dont know whole thing , even though i know few things how do i call xml in to c# code. in this i have few douts , am developing one application using asp.net with c# language,
the concept which is nothing but the how to insert text box value into xml using c#.net ,
acually i need the below output,
my sample output is:
="1.0"="utf-8"
<requestblock version="3.67">
<alias>testing</alias>
<request type="STORE">
<merchant>
<orderreference>EXAMPLE CARDSTORE</orderreference>
</merchant>
<operation>
<sitereference>live2</sitereference>
<accounttypedescription>CARDSTORE</accounttypedescription>
</operation>
<billing>
<town>mumbai</town>
<street>nehru nagr</street>
<postcode>6005432</postcode>
<premise>564</premise>
<payment type="VISA">
<pan>411123445234556677</pan>
<expirydate>10/13</expirydate>
</payment>
<name>
<first>test</first>
</name>
</billing>
</request>
</requestblock>
the thing is am getting the output which is in the unordered place, please find out my below code and let me know where i did mistake and give me a solution please...
Defaault.aspx.cs:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class sendrequest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
XmlDocument myxmldocument = new XmlDocument();
myxmldocument.Load(Server.MapPath("request.xml"));
XmlNode myxmlnode = myxmldocument.DocumentElement.FirstChild;
XmlElement myxmlelement = myxmldocument.CreateElement("billing");
myxmlelement.SetAttribute("town", Server.HtmlEncode(txttown.Text));
myxmlelement.SetAttribute("street", Server.HtmlEncode(txtstreet.Text));
myxmlelement.SetAttribute("postcode", Server.HtmlEncode(txtpostcode.Text));
myxmlelement.SetAttribute("premise", Server.HtmlEncode(txtpremise.Text));
myxmlelement.SetAttribute("pan", Server.HtmlEncode(txtpan.Text));
myxmlelement.SetAttribute("expirydate", Server.HtmlEncode(txtexpiry.Text));
myxmldocument.DocumentElement.InsertBefore(myxmlelement, myxmlnode);
myxmldocument.Save(Server.MapPath("request.xml"));
binddata();
lblwelcome.Text = "Record inserted Successfully Inside the XML Fil";
txttown.Text = "";
txtstreet.Text = "";
txtpremise.Text = "";
txtpostcode.Text = "";
txtpan.Text = "";
txtexpiry.Text = "";
}
private void binddata()
{
XmlTextReader myxmlreader = new XmlTextReader(Server.MapPath("request.xml"));
myxmlreader.Close();
}
}
request.xml:
="1.0"="utf-8"
<requestblock version="3.67">
<alias>testing</alias>
<request type="STORE">
<merchant>
<orderreference>EXAMPLE CARDSTORE</orderreference>
</merchant>
<operation>
<sitereference>live2</sitereference>
<accounttypedescription>CARDSTORE</accounttypedescription>
</operation>
<billing>
<town></town>
<street></street>
<postcode></postcode>
<premise></premise>
<payment type="VISA">
<pan></pan>
<expirydate></expirydate>
</payment>
<name>
<first></first>
</name>
</billing>
</request>
</requestblock>
the above code which was done by the mistakes output is:
="1.0"="utf-8"
<requestblock version="3.67">
<billing town="chennai" street="anna nagar" postcode="600034" premise="878" pan="411111887777766723" expirydate="10/13" />
<alias>testing</alias>
<request type="STORE">
<merchant>
<orderreference>EXAMPLE CARDSTORE</orderreference>
</merchant>
<operation>
<sitereference>live2</sitereference>
<accounttypedescription>CARDSTORE</accounttypedescription>
</operation>
<billing>
<town>
</town>
<street>
</street>
<postcode>
</postcode>
<premise>
</premise>
<payment type="VISA">
<pan>
</pan>
<expirydate>
</expirydate>
</payment>
<name>
<first>
</first>
</name>
</billing>
</request>
</requestblock>
so please follow my code and give me a solution....
thanks in advance....