XML viewer

XML viewer

Postby Antonio Linares » Wed Feb 27, 2013 3:44 pm

Now that we have started a way to easy retrieve all the items inside a XML file, now we can build a GUI viewer:

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

//----------------------------------------------------------------------------//


Image

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>
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Antonio Linares » Wed Feb 27, 2013 11:40 pm

Enhanced version that already shows items values on the right side:

xmltree.prg
Code: Select all  Expand view
#include "FiveWin.ch"
#include "Splitter.ch"

static oSplit1, oSplit2, oLbxDatas, oLbxMethods

//----------------------------------------------------------------------------/

function Test()

   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", "(c) FiveTech Software 2013" )
   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 {} ;
      SIZE 200, 200 PIXEL OF oWnd

   @ 0, 391 LISTBOX oLbxMethods VAR cMethod ITEMS {} ;
      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
      if oTagLast != nil
         if oTagLast:Depth() < oTagActual:Depth()
            ASize( aRoots, Len( aRoots ) + 1 )
            aRoots[ oTagActual:Depth() + 1 ] = aRoots[ oTagActual:Depth() ]:Add( oTagActual:cName )
            aRoots[ oTagActual:Depth() + 1 ]:Cargo = oTagActual:cData
         endif

         if oTagLast:Depth() > oTagActual:Depth()
            aRoots[ oTagActual:depth() + 1 ] = aRoots[ oTagActual:Depth() ]:Add( oTagActual:cName )
            aRoots[ oTagActual:depth() + 1 ]:Cargo = oTagActual:cData
         endif

         if oTagLast:Depth() == oTagActual:Depth()
            aRoots[ Max( oTagLast:Depth(), 1 ) ]:Add( oTagActual:cName ):Cargo = oTagActual:cData
         endif
      else
         AAdd( aRoots, oTree:Add( oTagActual:cName ) )
         ATail( aRoots ):Cargo = oTagActual:cData
      endif
      oTagLast = oTagActual
   end

   // HEval( oTagActual:aAttributes, { | cKey, cValue | MsgInfo( cKey, cValue )} )

   FClose( hFile )

   oTree:bChanged = { | oItem | oLbxDatas:SetItems( { oItem:GetSelected():Cargo } ) }

return nil

//----------------------------------------------------------------------------/


Image

test.xml
Code: Select all  Expand view
<xml>
<one>
<name>FiveWin</name>
<company>FiveTech Software
<country>Spain</country>
<region>EU</region>
</company>
</one>
<two attribute1="att1" attribute2="att2">
</two>
<three>
<first>any</first>
<second>value</second>
</three>
</xml>
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Antonio Linares » Thu Feb 28, 2013 12:03 am

This version already shows the items attributes at the right most listbox :-)

xmltree.prg
Code: Select all  Expand view
#include "FiveWin.ch"
#include "Splitter.ch"

static oSplit1, oSplit2, oLbxDatas, oLbxMethods

//----------------------------------------------------------------------------/

function Test()

   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", "(c) FiveTech Software 2013" )
   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 {} ;
      SIZE 200, 200 PIXEL OF oWnd

   @ 0, 391 LISTBOX oLbxMethods VAR cMethod ITEMS {} ;
      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
      if oTagLast != nil
         if oTagLast:Depth() < oTagActual:Depth()
            ASize( aRoots, Len( aRoots ) + 1 )
            aRoots[ oTagActual:Depth() + 1 ] = aRoots[ oTagActual:Depth() ]:Add( oTagActual:cName )
            aRoots[ oTagActual:Depth() + 1 ]:Cargo = oTagActual
         endif

         if oTagLast:Depth() > oTagActual:Depth()
            aRoots[ oTagActual:depth() + 1 ] = aRoots[ oTagActual:Depth() ]:Add( oTagActual:cName )
            aRoots[ oTagActual:depth() + 1 ]:Cargo = oTagActual
         endif

         if oTagLast:Depth() == oTagActual:Depth()
            aRoots[ Max( oTagLast:Depth(), 1 ) ]:Add( oTagActual:cName ):Cargo = oTagActual
         endif
      else
         AAdd( aRoots, oTree:Add( oTagActual:cName ) )
         ATail( aRoots ):Cargo = oTagActual
      endif
      oTagLast = oTagActual
   end

   FClose( hFile )

   oTree:bChanged = { | oItem | oLbxDatas:SetItems( { oItem:GetSelected():Cargo:cData } ),;
                                oLbxMethods:Reset(),;
                                HEval( oItem:GetSelected():Cargo:aAttributes,;
                                { | cKey, cData | oLbxMethods:Add( cKey + " : " + cData ) } ) }

return nil

//----------------------------------------------------------------------------/


Image

test.xml
Code: Select all  Expand view
<xml>
<one>
<name>FiveWin</name>
<company>FiveTech Software
<country>Spain</country>
<region>EU</region>
</company>
</one>
<two attribute1="att1" attribute2="att2">
</two>
<three>
<first>any</first>
<second>value</second>
</three>
</xml>
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Antonio Linares » Thu Feb 28, 2013 12:26 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Antonio Linares » Thu Feb 28, 2013 4:24 pm

This change may be required on Harbour Class TXmlDocument, upon some types of XML files:

METHOD New( xElem, nStyle ) CLASS TXMLDocument
Code: Select all  Expand view
        IF ! Empty( ::oRoot:oChild ) .AND. ::oRoot:oChild:cName == "xml" .and. ::oRoot:oChild:cData != nil
            ::cHeader := "<=xml " + ::oRoot:oChild:cData + "?>"
         ENDIF
 
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Silvio.Falconi » Fri Mar 01, 2013 9:38 am

Antonio,
if you try my test.xml you can see it show data only on first section and not on second section
Image

or I not understood to show the records

( I thinked show all data fields as vertical)
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: XML viewer

Postby Antonio Linares » Fri Mar 01, 2013 11:00 am

Silvio,

Please post here a copy of your XML file, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Silvio.Falconi » Fri Mar 01, 2013 9:21 pm

Code: Select all  Expand view


<?xml version="1.0" encoding="ISO-8859-1" ?>
<ROOT DATABASE="clienti.dbf">
  <Structure>
  <Field>
  <Field_name>CLNOMBRE</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        40</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLCIF</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        15</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLCATEGOR</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        40</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLNOTAS</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>       255</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLDIRECC</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        50</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLLOCALI</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        50</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLPAIS</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        30</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLTELEFONO</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        15</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLMOVIL</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        15</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLFAX</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        15</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLCONTACTO</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        40</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLEMAIL</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        50</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  <Field>
  <Field_name>CLURL</Field_name>
  <Field_type>Character</Field_type>
  <Field_length>        50</Field_length>
  <Field_decimals>         0</Field_decimals>
  </Field>
  </Structure>
  <Data>
  <Record>
    <CLNOMBRE>Clientes varios</CLNOMBRE>
    <CLCIF></CLCIF>
    <CLCATEGOR></CLCATEGOR>
    <CLNOTAS>m</CLNOTAS>
    <CLDIRECC></CLDIRECC>
    <CLLOCALI></CLLOCALI>
    <CLPAIS></CLPAIS>
    <CLTELEFONO></CLTELEFONO>
    <CLMOVIL></CLMOVIL>
    <CLFAX></CLFAX>
    <CLCONTACTO></CLCONTACTO>
    <CLEMAIL>l</CLEMAIL>
    <CLURL></CLURL>
  </Record>
  <Record>
    <CLNOMBRE>Empresa 1</CLNOMBRE>
    <CLCIF></CLCIF>
    <CLCATEGOR></CLCATEGOR>
    <CLNOTAS></CLNOTAS>
    <CLDIRECC></CLDIRECC>
    <CLLOCALI></CLLOCALI>
    <CLPAIS></CLPAIS>
    <CLTELEFONO></CLTELEFONO>
    <CLMOVIL></CLMOVIL>
    <CLFAX></CLFAX>
    <CLCONTACTO></CLCONTACTO>
    <CLEMAIL></CLEMAIL>
    <CLURL></CLURL>
  </Record>
  <Record>
    <CLNOMBRE>Empresa 2</CLNOMBRE>
    <CLCIF></CLCIF>
    <CLCATEGOR></CLCATEGOR>
    <CLNOTAS></CLNOTAS>
    <CLDIRECC></CLDIRECC>
    <CLLOCALI></CLLOCALI>
    <CLPAIS></CLPAIS>
    <CLTELEFONO></CLTELEFONO>
    <CLMOVIL></CLMOVIL>
    <CLFAX></CLFAX>
    <CLCONTACTO></CLCONTACTO>
    <CLEMAIL></CLEMAIL>
    <CLURL></CLURL>
  </Record>
</Data>
</ROOT>
 
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7056
Joined: Thu Oct 18, 2012 7:17 pm

Re: XML viewer

Postby Antonio Linares » Fri Mar 01, 2013 9:45 pm

Silvio,

Your XML is shown fine here. It just shows the data that there is inside the XML
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Otto » Fri Mar 01, 2013 10:40 pm

********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: XML viewer

Postby Antonio Linares » Sat Mar 02, 2013 9:46 am

Otto,

XML (extended markup language) is an evolution of the HTML, and is as simple as doing:

<anytag>any value</anytag>

they can be nested, without limits.

that easy :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Otto » Sat Mar 02, 2013 12:46 pm

Hello Antonio,
thank you. I posted the link to the PDF because I think this is a good explaination on page 3 of XML.
I use XML with FIVEWIN to exchange data for example with booking.com
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: XML viewer

Postby Antonio Linares » Sat Mar 02, 2013 2:43 pm

I was able to explain it in just three lines... ;-)

I love simplicity, but docs are fine too :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: XML viewer

Postby Marc Vanzegbroeck » Sat Mar 02, 2013 4:03 pm

Hi,

Is it also possible to use XML-files starting with:
Code: Select all  Expand view
<?xml version="1.0" encoding="UTF-16"?>
<MultiBlock xmlns="x-schema:ConfigFileSchema.xml">


If I read the file, the view is empty..
Regards,
Marc

FWH32+xHarbour | FWH64+Harbour | BCC | DBF | ADO+MySQL | ADO+MariaDB | ADO+SQLite
Marc Vanzegbroeck
 
Posts: 1159
Joined: Mon Oct 17, 2005 5:41 am
Location: Belgium

Re: XML viewer

Postby Antonio Linares » Sun Mar 03, 2013 8:08 am

Marc,

Could you post your XML file here ? Or send it to me by email, thanks :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42090
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 75 guests