Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

asp.net xmldatasource

Posted on 2015-02-15
11
Medium Priority
?
70 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 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 64

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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

704 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