Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

xml presented in a tree view

Posted on 2002-07-25
3
Medium Priority
?
905 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
3 Comments
 
LVL 7

Accepted Solution

by:
Cynna earned 300 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

[Webinar] Cloud Security

In this webinar you will learn:

-Why existing firewall and DMZ architectures are not suited for securing cloud applications
-How to make your enterprise “Cloud Ready”, and fix your aging DMZ architecture
-How to transform your enterprise and become a Cloud Enabler

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

916 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