Solved

TreeView w/ XmlDataSource

Posted on 2007-03-22
1
693 Views
Last Modified: 2012-08-13
I want to display some XML in a tree view control (ASP.net page).  Unfortunately I don't have much control over the XML source data.  I suppose I could create an XSLT document, but I really don't know what the incoming XML will look like.

Here is a sample of the XML:

<CAPI>
      <CAPI-PARAMETERS>
            <CAPI-FUNCTION>SCM</CAPI-FUNCTION>
            <CAPI-SYSTEM>CIS</CAPI-SYSTEM>
            <CAPI-DICTIONARY>HIST</CAPI-DICTIONARY>
            <CAPI-MENU>HIST</CAPI-MENU>
                <CAPI-OPID>WEB</CAPI-OPID>  
            <ENTER-SET>Y</ENTER-SET>
      </CAPI-PARAMETERS>
      <CAPI-DATA>
            <CIS-SVRC>
                  <PARM-LINE>71271136</PARM-LINE>
                  <HOME-PHONE>555/123-4567</HOME-PHONE>
                  <HOME-EXTN></HOME-EXTN>
                  <WORK-PHONE></WORK-PHONE>
                  <WORK-EXTN></WORK-EXTN>
                  <NAME>Smith, John</NAME>
                  <ATTN></ATTN>
                  <DLIN></DLIN>
                  <CHG-EFF-DT>30107</CHG-EFF-DT>
                  <CHG-SRCA>INET</CHG-SRCA>
                  <CHG-SRCB>INET</CHG-SRCB>
                  <CHG-SRCC>INET</CHG-SRCC>
                  <CHG-MOVE>123 Home St//55555</CHG-MOVE>
            </CIS-SVRC>
      </CAPI-DATA>
</CAPI>


As you can see, the XML is very basic, but it has a completely different structure each and every time (depending on which database table is be requested).




My current code looks something like this:


                XmlDataSource xmlSource = new XmlDataSource();
                xmlDs.Data = xml;   // this is obtained from the database
                xmlDs.DataBind();

                TreeView1.DataSource = xmlSource;
                TreeView1.DataBind();


This appears to work just fine, with the exception that it does not display data.  It only displays the column names, not the data in the columns.

That is, my results look like:

-CAPI
      -CAPI-PARAMETERS
            CAPI-FUNCTION
            CAPI-SYSTEM
            CAPI-DICTIONARY
            CAPI-MENU
                CAPI-OPID  
            ENTER-SET
            ...
            ..
            .
etc.

So how do I get the values to display as well without a lot of hassle?  I don't need anything fancy, I just need to tidy up the XML so it is easy to read.  It currently comes back as just one long string, and not formatted like my sample of the input source.
0
Comment
Question by:_TAD_
1 Comment
 
LVL 11

Accepted Solution

by:
ethoths earned 500 total points
ID: 18773087
If all you want to do is disoplay the xml in a structured format there are several ways to do it. You cold use xslt to just look for closing tags and put a crlf in the xml (as well as the appropriate number of tabs). I'm sure if you do a google you'll find an example of how do do this.

Another way would be to embed a browser control in your page and show the XML in that. That way you get color coding and brance collapsing all for free.


0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 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

12 Experts available now in Live!

Get 1:1 Help Now