Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net xml

Posted on 2015-02-14
7
Medium Priority
?
114 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 34

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 34

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 34

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
Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

 
LVL 34

Expert Comment

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

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 34

Accepted Solution

by:
Mike Eghtebas earned 2000 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
 
LVL 1

Author Closing Comment

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

719 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