Solved

TreeView w/ XmlDataSource

Posted on 2007-03-22
1
696 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 Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

860 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