Solved

asp.net xml

Posted on 2015-02-14
7
103 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
Comment Utility
        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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
asp outputHere is asp output:
0
 

Author Comment

by:ITsolutionWizard
Comment Utility
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
Comment Utility
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
Comment Utility
no problem. I will post it soon. thank you for your helps.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

10 Experts available now in Live!

Get 1:1 Help Now