viewtopic.php?f=3&t=25741
xmltree.prg
- Code: Select all Expand view
- #include "FiveWin.ch"
#include "Splitter.ch"
static oSplit1, oSplit2, oLbxDatas, oLbxMethods
//----------------------------------------------------------------------------//
function Main()
local oWnd
DEFINE WINDOW oWnd TITLE "XML viewer" ;
MENU BuildMenu()
ACTIVATE WINDOW oWnd ;
ON INIT BuildTree( oWnd ) ;
ON RESIZE ( If( oSplit1 != nil, oSplit1:AdjLeft(),),;
If( oSplit2 != nil, oSplit2:AdjRight(),) )
return nil
//----------------------------------------------------------------------------//
function BuildMenu()
local oMenu
MENU oMenu
MENUITEM "About" ACTION MsgAbout( "XML Viewer", "FiveTech Software" )
ENDMENU
return oMenu
//----------------------------------------------------------------------------//
function BuildTree( oWnd )
local oTree := TTreeView():New( 0, 0, oWnd )
local oClass, cData, cMethod
local hFile, oXmlDoc, oXmlIter, oTagActual
local oTagLast, aRoots := {}
oTree:nWidth = 180
// oTree:SetImageList( oImageList )
oTree:Expand()
@ 0, 186 LISTBOX oLbxDatas VAR cData ITEMS { "one", "two", "three" } ;
SIZE 200, 200 PIXEL OF oWnd
@ 0, 391 LISTBOX oLbxMethods VAR cMethod ITEMS { "one", "two", "three" } ;
SIZE 200, 200 PIXEL OF oWnd
@ 0, 181 SPLITTER oSplit1 ;
VERTICAL ;
PREVIOUS CONTROLS oTree ;
HINDS CONTROLS oLbxDatas ;
LEFT MARGIN 150 ;
RIGHT MARGIN oSplit2:nLast + 100 ;
SIZE 4, 300 PIXEL ;
OF oWnd STYLE
@ 0, 386 SPLITTER oSplit2 ;
VERTICAL ;
PREVIOUS CONTROLS oLbxDatas ;
HINDS CONTROLS oLbxMethods ;
LEFT MARGIN oSplit1:nFirst + 120 ;
RIGHT MARGIN 80 ;
SIZE 4, 300 PIXEL ;
OF oWnd STYLE
hFile = FOpen( "test.xml" )
oXmlDoc = TXmlDocument():New( hFile )
oXmlIter = TXmlIterator():New( oXmlDoc:oRoot )
AAdd( aRoots, oTree )
while ( oTagActual := oXmlIter:Next() ) != nil
// aRoots[ oTagActual:Depth() ]:Add( oTagActual:cName )
// oRoot:Add( oTagActual:cName )
if oTagLast != nil
if oTagLast:Depth() < oTagActual:Depth()
ASize( aRoots, Len( aRoots ) + 1 )
aRoots[ oTagActual:Depth() ] = aRoots[ oTagActual:Depth() - 1 ]:Add( oTagActual:cName )
// MsgInfo( oTagActual:cName + ", " + "open node", oTagActual:Depth() )
endif
if oTagLast:Depth() > oTagActual:Depth()
aRoots[ oTagActual:Depth() - 1 ]:Add( oTagActual:cName )
// MsgInfo( oTagActual:cName + ", " + "close node", oTagActual:Depth() )
endif
if oTagLast:Depth() == oTagActual:Depth()
aRoots[ Max( oTagLast:Depth() - 1, 1 ) ]:Add( oTagActual:cName )
// MsgInfo( oTagActual:cName + ", " + "keeps node", oTagActual:Depth() )
endif
else
AAdd( aRoots, oTree:Add( oTagActual:cName ) )
// MsgInfo( oTagActual:cName + ", " + "starts", oTagActual:Depth() )
endif
oTagLast = oTagActual
end
// HEval( oTagActual:aAttributes, { | cKey, cValue | MsgInfo( cKey, cValue ) } )
FClose( hFile )
// oTree:bChanged = { || ShowClassInfo( oTree ) }
return nil
//----------------------------------------------------------------------------//
test.xml
- Code: Select all Expand view
- <xml>
<one>
<name>FiveWin</name>
<company>FiveTech Software</company>
</one>
<two attribute1="att1" attribute2="att2">
</two>
<three>
</three>
</xml>