Solved

TreeView w/ XmlDataSource

Posted on 2007-03-22
1
694 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 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

20 Experts available now in Live!

Get 1:1 Help Now