Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

interpretation of an xml xHarbour HwGUI

131 views
Skip to first unread message

Alexandre Bencz

unread,
May 18, 2012, 1:58:09 PM5/18/12
to
Hello ..
I'm having problems reading and interpretation of an XML ...
Well, as I intended to get an xml file that was typed by someone, and
interpret it, this xml will contain the information to a graphical
interface that will be generated by HWGUI, the XML that I have thought
of being interpreted is the following ...


<?xml version="1.0"?>
<catalog>
<command id="window">
<name>Form1</name>
<width>300</width>
<height>300</height>
<caption>Sair</caption>
</command>

<command id="button">
<name>BTM</name>
<width>20</width>
<height>20</height>
<caption>Sair</caption>
</command>
</catalog>

but I believe that to leave the XML easier to read and to write
something like:


<?xml version="1.0"?>
<catalog>
<command id="window">
<name>Form1</name>
<width>300</width>
<height>300</height>
<caption>Sair</caption>
<internal>
<command id="button">
<name>BTM</name>
<width>20</width>
<height>20</height>
<caption>Sair</caption>
</command>
</internal>
</command>
</catalog>

Well, I made the code to read, he can read, but at the time of
interpretation, I have serious problems ...
see my code ...


#include "hbxml.ch"
#include "hbclass.ch"
#include "hwgui.ch"

class xml_read
private:
data FileName init ""
data cString
data oFile
data oFileScan
data oCommand
data oIterator, oCurrent

data width, height init 0
data caption, name

public:
method new( oFileName ) constructor
method open()
method read()
method window( oName, oWidth, oHeight, oCaption )
endclass

method new( oFileName ) class xml_read
::FileName := oFileName
? "Criando classe >> xml_read << :: arquivo carregado: "
+ ::FileName
::open()
return self

method open() class xml_read
? "Iniciando leitura " + ::FileName
::cString := memoread( ::FileName )
? "Arquivo " + ::FileName + " lido"

if .not. len( ::cString ) > 0
wait "entre com o arquivo XML"
return nil
endif

::oFile := TXmlDocument( ::cString, HBXML_STYLE_NOESCAPE )
if .not. ::oFile:nError == HBXML_ERROR_NONE
wait "erro ao ler o arquivo xml: " + str( ::oFile:nError )
return nil
endif

::read()

return nil

method read() class xml_read
::oFileScan := TXmlIteratorScan():New( ::oFile:oRoot )
::oCommand := ::oFileScan:find( "command" )

if ::oCommand == NIL
wait " nenhum comando encontrado"
return nil
endif

do while .t.
::oIterator := TXmlIterator():New( ::oCommand )

if HHasKey( ::oCommand:aAttributes, "id" )
if ::oCommand:aAttributes["id"] == "window"
? ::oCommand:aAttributes["id"] + " -> "
+ ::oCommand:aAttributes["id"]
do while .t.
::oCurrent := ::oIterator:Next()
if ::oCurrent == NIL
exit
else
do while .t.
::oCurrent := ::oIterator:Next()
if ::oCurrent == NIL
exit
elseif ::oCurrent:cName == "width"
::width := ::oCurrent:cData
elseif ::oCurrent:cName == "height"
::height := ::oCurrent:cData
elseif ::oCurrent:cName == "name"
::name := ::oCurrent:cData
elseif ::oCurrent:cName == "caption"
::caption := ::oCurrent:cData
else
MessageBox(::oCurrent:cData + " nao é valido", "Erro")
endif
enddo
endif
enddo
::window(::name, ::width, ::height, ::caption)
endif
else
? "sem atribuicao"
endif

/*::oIterator := TXmlIterator():New( ::oCommand )
do while .t.
::oCurrent := ::oIterator:Next()
if ::oCurrent == NIL
? "=> Final da ramificacao <="
wait
exit
else
? "Current tag: " + ::oCurrent:cName + " -> Value: "
+ ::oCurrent:cData

endif
enddo
??
?*/

::oCommand := ::oFileScan:FindNext()
if ::oCommand == NIL
? "sem mais comandos"
wait
exit
endif
enddo
return nil

method window( oName, oWidth, oHeight, oCaption ) class xml_read
local oDlg
oDlg := oName

INIT DIALOG oDlg TITLE oCaption ;
AT 0,-130 SIZE oWidth,oHeight NOEXIT ;
STYLE WS_POPUP+WS_CAPTION+WS_SYSMENU+WS_SIZEBOX+DS_CENTER
Thisform := oDlg

ACTIVATE DIALOG oDlg

return oDlg:lresult


**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**
** **
// Main Function **
** **

**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**8**

function main()
local oXML := xml_read("test_gui.xml")
wait
return nil

my problem .... is that I can not generate the interface, and add the
components in the form ... based on the information contained in
XML .... :X
Well ... I wonder, how can I do to solve this my problem?

Thanks

cul...@gmail.com

unread,
May 21, 2012, 6:23:12 AM5/21/12
to
Alexandre

use the hwgui classes to do this

see the hwgui\utils\designer\samples folder to see how to work with
direct xml screens

Regards
Luiz
0 new messages