如何使用带有c#langauge的asp.net将文本框值插入到xml中? [英] how to insert textbox value into xml using asp.net with c# langauge?
问题描述
大家好,
我刚进入xml,我不知道整件事情,尽管我知道如何将xml调用到c#代码。在这个我有几个douts,我正在使用带有c#语言的asp.net开发一个应用程序,
这个概念只不过是如何使用c#.net将文本框值插入xml,
我需要以下输出,
我的样本输出是:
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:
<?xml version="1.0" encoding="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>
我得到的输出是在无序的地方,请找出我的下面的代码让我知道我错在哪里并给我一个解决方案请...
Defaault.aspx.cs:
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:
request.xml:
<?xml version="1.0" encoding="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:
<?xml version="1.0" encoding="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....
推荐答案
http://www.aspdotnet- suresh.com/2010/12/how-to-insert-data-into-xml-and-how-to.html [ ^ ]
这篇关于如何使用带有c#langauge的asp.net将文本框值插入到xml中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!