Solved

asp.net xml

Posted on 2015-02-14
7
104 Views
Last Modified: 2015-02-15
Can you show me how to call BondAmount in asp.net/c# ?
I basically want to get the list of bond amount so i will be

10000
15000

Thanks

<Bonds>
<Bond>
    <State>CA</State>
    <BondAmountListing>
      <BondAmount>10000</BondAmount>
      <BondAmount>15000</BondAmount>
     
    </BondAmountListing>
 /Bond>
</Bonds>
0
Comment
Question by:ITsolutionWizard
  • 5
  • 2
7 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40610522
        private void button1_Click(object sender, EventArgs e)
        {

            XDocument d = XDocument.Load("XMLFile1.xml");

            var amounts = d.Descendants( "BondAmount" );

            foreach ( var amount in amounts)
            {
                MessageBox.Show(amount.Value.ToString());
            }
        }

Open in new window


Make sure to select XMLFile1.xml in the Solution Explorer and hit F4 to change its Copy to Output Directory property to "Copy always"
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40610526
I tested the solution, I got:
xml
I realize that you are using asp but the looping code is the same, In place of MessageBox( user Response.Write(
Mike
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40610530
Here is asp version:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        XDocument d = XDocument.Load("C:\\Users\\Mike\\Documents\\EE\\WebSite5\\XMLFile.xml");

        var amounts = d.Descendants("BondAmount");

        foreach (var amount in amounts)
        {
            Response.Write(amount.Value.ToString() + "\n");
        }
    }
}
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40610538
asp outputHere is asp output:
0
 

Author Comment

by:ITsolutionWizard
ID: 40610580
actually i forgot something i want to use gridview and xmldatasource. sorry my bad.
can you show me how? thanks
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40610975
That is okay, you can always post a new question. But close this one because the content needs to match the original post. Even after the gridview question, there will be many other questions coming.

Mean while I prepare the groundwork for your new question.

Mike
0
 

Author Closing Comment

by:ITsolutionWizard
ID: 40611043
no problem. I will post it soon. thank you for your helps.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now