how to use xml file in asp.net ?

I have a following xml file . In the run time i need to assign the values for each node .
how to do this ?
<RequestBlock Version="3.51">
    <Request Type="AUTH">
        <Operation>
            <Amount>1099</Amount>
            <Currency>GBP</Currency>
            <SiteReference>amdnsdns225882211dshfsdhfhd</SiteReference>
            <SettlementDay>1</SettlementDay>
        </Operation>
        <CustomerInfo>
            <Postal>
                <Name>
                    <NamePrefix>Mr.</NamePrefix>
                    <FirstName>Joe</FirstName>
                    <MiddleName>A.</MiddleName>
                    <LastName>Bloggs</LastName>
                    <NameSuffix>CEng.</NameSuffix>
                </Name>
                <Company>Test Company</Company>
                <Street>A Street</Street>
                <City>A City</City>
                <StateProv>A State</StateProv>
                <PostalCode>A Postcode</PostalCode>
                <CountryCode>GB</CountryCode>
            </Postal>
            <Telecom>
                <Phone>0000111111</Phone>
            </Telecom>
            <Online>
                <Email>yahoo@live.com</Email>
            </Online>
        </CustomerInfo>
        <PaymentMethod>
            <CreditCard>
                <Type>Visa</Type>
                <Number>25555555555555</Number>
                <ExpiryDate>01/2013</ExpiryDate>
            <SecurityCode>255555</SecurityCode>
            </CreditCard>
        </PaymentMethod>
        <Order>
            <OrderReference>Order0001</OrderReference>
            <OrderInformation>This is a test order</OrderInformation>
        </Order>
    </Request>
    <Certificate>*abcdn25850999xxxxxxxxxx545888</Certificate>
</RequestBlock>
VarshiniAsked:
Who is Participating?
 
wdosanjosConnect With a Mentor Commented:
Please check if the following addresses your need:

var xml = File.ReadAllText(@"C:\temp\template.xml");	// Loads your file to memory (could be a static variable)

// Assign attributes
var doc = new System.Xml.XmlDocument();

doc.PreserveWhitespace = true;

doc.LoadXml(xml);

var root = doc.DocumentElement;

root.SelectSingleNode("Request/Operation/Amount").InnerText = "123.45";
root.SelectSingleNode("Request/Operation/Currency").InnerText = "USD";
// other assignments go here

var updatexml = doc.OuterXml;	// 'updatedxml' contains the xml with the attributes updated

Open in new window

0
 
roshnipatelCommented:
Here's a great example in ASP.NET
http://www.4guysfromrolla.com/articles/092403-1.aspx#postadlink

But in short, you want to use XMLTextWriter
0
 
wdosanjosCommented:
You can do something like this:

var doc = new System.Xml.XmlDocument();

doc.PreserveWhitespace = true;

doc.Load(@"C:\temp\template.xml"); // Your XML file

var root = doc.DocumentElement;

root.SelectSingleNode("Request/Operation/Amount").InnerText = "123.45";
root.SelectSingleNode("Request/Operation/Currency").InnerText = "USD";

// etc

Console.WriteLine(doc.OuterXml);

Open in new window

0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
VarshiniAuthor Commented:
i do not want to physically write to the file. Since i am using asp.net application just i need to read the xml file to memory and using the xml i need write .
0
 
Asim NazirCommented:
hi,

I think load dataset from this xml using LoadFromXml of Ado.Net and you can play with it further using datatable.

Asim
0
 
Asim NazirCommented:
hi,

I think load dataset from this xml using LoadFromXml of Ado.Net and you can play with it further using datatable.

Asim
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.