Solved

xml presented in a tree view

Posted on 2002-07-25
3
897 Views
Last Modified: 2012-06-21
I have an xml file with around 500 records. I want my user to browse the xml file via a tree view. is this possible.

thnks in advance.
0
Comment
Question by:drnadeem
[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
3 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 100 total points
ID: 7178548

Yes it is, but you need XML parser for this. This is a bit of work, but there is
no need to develop your own. You have two choices:

1. Use Microsoft XML ActiveX component. You need to import Microsoft XML type library
   for this (Project -> Import type library -> Microsoft XML <version xxx>).
   This is slightly modified code from borland.public.delphi.xml that does what you want:


procedure XMLFile2TreeView(XMLDocFileName: String; TV:TTreeView); // Parses and transfers xml file to a treeview
var DOM: IXMLDOMDocument;
  procedure AddNodes(XMLNode: IXMLDOMNode; TreeNode: TTreeNode);
  var Index: Integer;
      NewNode: TTreeNode;
      Value: string;
  begin
    if XMLNode.nodeType in [NODE_TEXT, NODE_CDATA_SECTION, NODE_COMMENT] then
      Value := XMLNode.text
    else
      Value := XMLNode.nodeName;
    NewNode := TV.Items.AddChild(TreeNode,
    XMLNode.nodeTypeString + ': ' + Value);
    for Index := 0 to XMLNode.childNodes.length - 1 do
        AddNodes(XMLNode.childNodes.item[Index], NewNode);
  end;
begin
  DOM := CoDOMDocument.Create;
  DOM.load(XMLDocFileName);
  with TV do begin
       try
          Items.BeginUpdate;
          Items.Clear;
          AddNodes(DOM, nil);
          Items[0].Expand(True);
          TopItem := Items[0];
       finally
          Items.EndUpdate;
       end;
  end;
end;

// DEMO (requires Button1 and TreeView1 on the form, uses MSXML_TLB):
//------------------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
  XMLFile2TreeView('demo.xml', TreeView1);
end;



2. Use custom XML parser component, for example:  http://www.destructor.de/xmlparser/

0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7179081
or embed a webbrowser and just load the file in the embedded webbrowser :)
0
 
LVL 1

Author Comment

by:drnadeem
ID: 7183139
the component worked 4 me
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Printing problem 2 124
Unique identifier on a terminal server (rdp) 4 85
Browsing a TTreeView in Delphi 5 49
Firemonkey how to swip panel with finger tap 1 42
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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