interpretação de um xml

Projeto HwGui - Biblioteca visual para Harbour/xHarbour

Moderador: Moderadores

Avatar do usuário
bencz
Usuário Nível 4
Usuário Nível 4
Mensagens: 524
Registrado em: 28 Abr 2012 17:36
Contato:

interpretação de um xml

Mensagem por bencz »

Olá...
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>
mas.... imagino q de para deixar ele mais simples de se ler, algo como:

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>
Bom, fiz o código para ler, ele consegue ler, mas no momento da interpretação, tenho sérios problemas...
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
Bom.... então, gostaria de saber, como posso fazer p/ resolver esse meu problema ??
obrigado
Editado pela última vez por Pablo César em 15 Mai 2012 13:46, em um total de 1 vez.
Razão: O presente tópico foi movido da seção Harbour, uma vez que seu conteúdo tem mais a ver com relação Hwgui.
Imagem
Avatar do usuário
bencz
Usuário Nível 4
Usuário Nível 4
Mensagens: 524
Registrado em: 28 Abr 2012 17:36
Contato:

interpretação de um xml

Mensagem por bencz »

o meu problema.... eh q eu nao consigo gerar a interface, e adicionar os componentes no form... apartir das informações contidas no XML.... :X
Imagem
Avatar do usuário
sygecom
Administrador
Administrador
Mensagens: 7131
Registrado em: 21 Jul 2006 10:12
Localização: Alvorada-RS
Contato:

interpretação de um xml

Mensagem por sygecom »

Amiguinho sem nome.
Acontece que esses XML não foram gerados pela IDE e nem estão baseados na estrutura que a Hwgui lê, o que você está querendo é montar um XML na sua estrutura e lê o mesmo, então você deve alterar os FONTES da Hwgui para interpretar esse seu layout.
Leonardo Machado
xHarbour.org + Hwgui + PostgreSql
Avatar do usuário
bencz
Usuário Nível 4
Usuário Nível 4
Mensagens: 524
Registrado em: 28 Abr 2012 17:36
Contato:

interpretação de um xml

Mensagem por bencz »

Mas então, nao existe uma forma com que eu possa realizar isso, sem realizar essas alterações nos fontes do HWGUI ??
apenas lendo o XML e gerando o GUI ?
que é basicamente oque estou querendo....

Bom... o trabalho pode ser bem grande, eu sei, mas se eu conseguir apenas que crie o form... e adicione os componentes internos, tipo, os botoes ou text box, eu jah iria conseguir fazer o resto, com muita tranquilidade... ;x
se puderem me ajudar, a fazer pelo menos esse basico, eu agradeço e muito :S
Imagem
Responder