Solved

xml presented in a tree view

Posted on 2002-07-25
3
896 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

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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