Estou com problemas na leitura e interpretação de um XML...
Bom, tenho como por objetivo pegar um xml q foi digitado por alguem, e interpretar ele, esse xml vai conter as informações para uma interface grafica, q vai ser gerada pela HWGUI, o XML q eu tenho por idéia de ser interpretado é o seguinte...
Código: Selecionar todos
<?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>
Código: Selecionar todos
<?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>
vejam o meu código...
Código: Selecionar todos
#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
obrigado


