Solved

asp.net xmldatasource

Posted on 2015-02-15
11
54 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 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
Comment Utility
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
Comment Utility
Ic but I would like to keep my way in xml. Is it possible?
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
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
 

Author Comment

by:ITsolutionWizard
Comment Utility
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
Comment Utility
Overall, I appreciate your helps but I need to keep using same xml file format because it is currently in production website.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
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 33

Expert Comment

by:Mike Eghtebas
Comment Utility
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
Comment Utility
I try xpath but always return first record only
0
 
LVL 33

Expert Comment

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

Mike
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
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 62

Expert Comment

by:Fernando Soto
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

17 Experts available now in Live!

Get 1:1 Help Now