Solved

asp.net xmldatasource

Posted on 2015-02-15
11
64 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
  • 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
 

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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
 

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
 

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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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