Solved

TreeView w/ XmlDataSource

Posted on 2007-03-22
1
698 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_
[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
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How do I bind a WPF ComboBox to an ItemSource using XAML? 2 28
Get sourcecode path 14 46
C# XML Get Values 4 33
Visual Studio 2015 auto inserted code 12 65
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

735 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