[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

how to use xml file in asp.net ?

Posted on 2011-04-21
6
Medium Priority
?
231 Views
Last Modified: 2012-05-11
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>
0
Comment
Question by:Varshini
6 Comments
 
LVL 2

Expert Comment

by:roshnipatel
ID: 35442734
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
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35442819
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
 

Author Comment

by:Varshini
ID: 35443226
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Accepted Solution

by:
wdosanjos earned 2000 total points
ID: 35443350
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
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35443678
hi,

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

Asim
0
 
LVL 10

Expert Comment

by:Asim Nazir
ID: 35453812
hi,

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

Asim
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question