Solved

asp.net xmldatasource

Posted on 2015-02-15
11
69 Views
Last Modified: 2015-02-16
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

and I would like to use xmldatasource and gridview as front end.

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
  • 6
  • 4
11 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40611203
I revised the XML a bit for test purpose (I was getting errors with your version):
<?xml version="1.0" encoding="utf-8" ?>
<Bonds>
  <Bond ID="1">
     <State>CA</State>
      <BondAmount>10000</BondAmount>
    </Bond>
  <Bond ID="2">
    <State>CA</State>
    <BondAmount>15000</BondAmount>
  </Bond>
  <Bond ID="3">
    <State>MA</State>
    <BondAmount>8000</BondAmount>
  </Bond>
  <Bond ID="4">
    <State>MA</State>
    <BondAmount>9000</BondAmount>
  </Bond>
  </Bonds>

Open in new window

Using this code: (make sure to add: using System.Data;)
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(MapPath("~/XMLFile1.xml"));
        GridView1.DataSource = ds;
        GridView1.DataBind();
 
    }

Open in new window

I got this:xml to gv
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611266
Ic but I would like to keep my way in xml. Is it possible?
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611286
I found the error:

    </BondAmountListing>
 </Bond>      // < was missing.
</Bonds>

I tried different variations of it but I was not able to figure it out. I guess I need to learn more about xml myself.
I can post a new question on that saying I have this c# code that works with this xml but not the other one (the one you have). then I let you know about the solution. Or, you can post it yourself.

Let me know which way you prefer.

Mike
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611297
try below
</Bond>   is mssing "/", and i correct below. I think the xml is valid.


<Bonds>
<Bond>
    <State>CA</State>
    <BondAmountListing>
      <BondAmount>10000</BondAmount>
      <BondAmount>15000</BondAmount>
     
    </BondAmountListing>
< /Bond>
</Bonds>
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611302
Overall, I appreciate your helps but I need to keep using same xml file format because it is currently in production website.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611321
I suppose you neither want me to post the question nor you want to do it yourself. Then, I am sure another expert will join and make contribution you need.

Thanks,

Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611336
I would suggest to delete this question (refunding the points) and then posting a new question because with zero comments on a question, you will have a better chance of getting quick response.

BTW, I check your xml file at http://www.xmlvalidation.com/ and there was no error. I think xPath query will do the job.

Mike
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611546
I try xpath but always return first record only
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611631
I will invite another expert who often helps me with my question. I am sure he will a solution right away.

Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611645
re: I try xpath but always return first record only

With the code I have submitted, using your xml file I also get result similar to yours. Now, there are two possibilities:

A: Your xml design is not good and that is why it is not producing the expected result.
B: Your xml is good and someone who knows how to handle it needs to take a look at it.

I sent an email to Fernando Soto to take a look at this question and teach us how it is done.

Mike
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 40612293
Hi ITsolutionWizard and Mike;

I wish I can help with this question but do not have the expertise to help. What I can tell you is the current XML document will NOT be able to be displayed in the GridView because it works with XML Attributes and NOT inner values. That said you have two options. First is to modify the XML document so that the values are Attributes of the node. But you stated that you can not do that, so the only option is to transform the XML document into the correct format. So you must create a XSLT document describing how do you want to transform the XML document into the correct format. When you have this document added into your project when you configure the XmlDataSource you provide the path to the file to the, Transform File Property. Because XSLT documents are Greek to me I can not direct you in this matter.

Maybe you can post a new question specifically asking help in creating an XSLT document to convert your XML at runtime.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
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…

631 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