Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Stefan Wuebbe
  Where is Stefan Wuebbe?
 Hamburg
 Germany
 Stefan Wuebbe
 To: Yousfi Benameur
  Where is Yousfi Benameur?
 El Bayadh
 Algeria
 Yousfi Benameur
 Tags
Subject: RE: xml and treeview
Thread ID: 298747 Message ID: 298771 # Views: 84 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: Active X Controls & OLE Automation
Date: Friday, March 18, 2011 8:46:56 AM         
   


Salut Yousfi,

> 1. I have a treeview and i want to export it to an XML file(let i say saving the treeview to an xml file).
> is the cursortoXML is the only one method from vfp ?converting treeview to dbf and cursortoXMl: is there another solution ?
>

It's not the only one, but I'd say it's probably the easiest since tree views might work well with a "flat", denormalized data source anyway.
You can however also use the XMLAdapter class, or MS XML DOM (most powerful), or even generate "manually" via StrToFile (worst option IMO).

> i want also to preserve the exact order of the treeview branches.

That might be no problem since XML actually has a kind of physical order (as opposed to the SQL concept).

> 2. I want also the reversible operation: having an xml (any): how to convert it into a treeview (populate the treeview).
>
> all in vfp code.Thanks in advance.

If I gt your description right, it might boil down to use XMLToCursor for "reading" the input.XML, and CursorToXML for writing the output.XML, so I think the sample pasted below is not very extraordinary.


hth
-Stefan



* test data (normalized)
CREATE CURSOR continents (con_id I, con_name C(20))
INSERT INTO continents VALUES (1, 'Africa')
INSERT INTO continents VALUES (2, 'America')
INSERT INTO continents VALUES (3, 'Asia')
CREATE CURSOR countries (cou_id I, con_id I, cou_name C(20))
INSERT INTO countries VALUES (1, 1, 'Algeria')
INSERT INTO countries VALUES (2, 1, 'Egypt')
INSERT INTO countries VALUES (3, 2, 'Argentina')
INSERT INTO countries VALUES (4, 2, 'Brasil')
INSERT INTO countries VALUES (5, 3, 'China')
INSERT INTO countries VALUES (6, 3, 'India')

* treeview's data source: denormalized "flat file"
SELECT con_name, cou_name ;
	FROM continents CO ;
	JOIN countries CU ON CU.con_id = CO.con_id ;
	INTO CURSOR crsTreeview

* treeview's actual data-source file is XML
CURSORTOXML('crsTreeview','test55input.xml',1,512)

* tree view
_screen.AddObject('tree','myTreeContainer')
_screen.tree.Visible = .T.
_screen.tree.SaveXML()

RETURN



DEFINE CLASS myTreeContainer as Container
	BackStyle = 0
	BorderWidth = 0
	Width = 200
	Height = 200
	cTempCursor = SYS(2015)

	PROCEDURE Init
		LOCAL lnSelect
		lnSelect = SELECT(0)
		XMLTOCURSOR('test55input.xml',This.cTempCursor,512)

		LOCAL loNode, lcContinent
		lcContinent = ''
		SCAN
			IF !( con_name == m.lcContinent )
				lcContinent = con_name
				loNode = _screen.tree.oleTree.Nodes.Add(,1,m.lcContinent,con_name,0)
				loNode.Expanded = .T.
			ENDIF
			loNode = _screen.tree.oleTree.Nodes.Add(m.lcContinent,4,SYS(2015),cou_name,0)
		ENDSCAN

		SELECT (m.lnSelect)
	ENDPROC
	PROCEDURE SaveXML
		CURSORTOXML(This.cTempCursor,'test55output.xml',1,512)
	ENDPROC

	ADD OBJECT oleTree as oleControl WITH ;
		OleClass = 'MSComctlLib.TreeCtrl.2', Width = 200, Height = 200
ENDDEFINE


COMPLETE THREAD

xml and treeview Posted by Yousfi Benameur @ 3/18/2011 1:29:49 AM
RE: xml and treeview Posted by Stefan Wuebbe @ 3/18/2011 8:46:56 AM
RE: xml and treeview Posted by Yousfi Benameur @ 3/18/2011 10:15:14 AM
RE: xml and treeview Posted by Stefan Wuebbe @ 3/18/2011 10:58:23 AM
RE: xml and treeview Posted by Yousfi Benameur @ 3/18/2011 11:36:32 AM
RE: xml and treeview Posted by Stefan Wuebbe @ 3/18/2011 6:55:26 PM
RE: xml and treeview Posted by Yousfi Benameur @ 3/18/2011 10:25:48 PM
RE: xml and treeview Posted by Stefan Wuebbe @ 3/19/2011 11:24:20 AM
RE: xml and treeview Posted by Yousfi Benameur @ 3/20/2011 12:08:32 AM
RE: xml and treeview Posted by Koen Piller @ 3/19/2011 12:49:26 PM
RE: xml and treeview Posted by Yousfi Benameur @ 3/19/2011 5:28:17 PM
RE: xml and treeview Posted by Koen Piller @ 3/19/2011 6:07:56 PM
RE: xml and treeview Posted by Bob Brook @ 3/18/2011 12:05:13 PM
RE: xml and treeview Posted by Yousfi Benameur @ 3/18/2011 2:38:15 PM
RE: xml and treeview Posted by Yousfi Benameur @ 3/18/2011 6:06:14 PM
RE: xml and treeview Posted by James Frye @ 3/21/2011 2:48:49 PM
RE: xml and treeview Posted by Yousfi Benameur @ 3/21/2011 4:55:56 PM