We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

how to use xml file in asp.net ?

Varshini
Varshini asked
on
Medium Priority
245 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>
Comment
Watch Question

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
Top Expert 2011

Commented:
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

Author

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 .
Top Expert 2011
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Asim NazirProject Manager

Commented:
hi,

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

Asim
Asim NazirProject Manager

Commented:
hi,

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

Asim
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.