cAppConfig Class usage example

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Modules > AppConfig > cAppConfig Class >

cAppConfig Class usage example


cAppConfig class usage example


Imagine your XML configuration file like the following:


<?xml version="1.0" encoding="utf-8"?>


   <!--this is a comment-->















      <Buffer1><![CDATA[some stuff]]></Buffer1> <!-- Comment -->











The following code will list all the nodes present in the XML configuration file and will show some of their values


uses "Console"

uses "AppConfig"


function TBMain() as long


end function


function LoadAppConfig() as Long

  dim MyAppConfig as new cAppConfig'(APP_SourcePath & "MyAppConfig.xml")

  dim nKeys       as Long

  dim lIdx        as Long


  PrintL "Active ProgId object is:", MyAppConfig.ProgId

  'MyAppConfig.ProgId = "Msxml2.DOMDocument"

  'printl "Active activex object", MyAppConfig.ProgId



  MyAppConfig.Load(APP_SourcePath & "MyAppConfig.xml")

  'MyAppConfig.LoadXML(Load_File(APP_SourcePath & "MyMyAppConfig.xml"))


  if MyAppConfig.ErrorPresent Then

    '---Some error occurred

    PrintL "Error code", MyAppConfig.ErrorCode

    PrintL "Error description", MyAppConfig.ErrorDescription


    '---No errors, we can go on


    printl "List all nodes present into configuration file:" in %CCOLOR_FYELLOW

    nKeys = MyAppConfig.GetKeyCount

    printl "Number of keys found:", nKeys

    for lIdx = 1 to nKeys

      printl $tab, lIdx, MyAppConfig.GetKeyName(lIdx)




    PrintL "Show some specific nodes data:" in %CCOLOR_FYELLOW

    PrintL "AppVersion.............", MyAppConfig.GetKey("AppVersion")

    PrintL "AppData\Author_eMail...", MyAppConfig.GetKey("AppData\Author_eMail")

    PrintL "AppData\Author_WebSite.", MyAppConfig.GetKey("AppData\Author_WebSite")

    PrintL "AppFiles\File1.........", MyAppConfig.GetKey("AppFiles\File1")

    PrintL "AppFiles\File2.........", MyAppConfig.GetKey("AppFiles\File2")

    PrintL "Buffers\Buffer1........", MyAppConfig.GetKey("Buffers\Buffer1")

    PrintL "DB\ConnectionString....", MyAppConfig.GetKey("DB\ConnectionString")


  end if


  PrintL "Press a key to end" in %CCOLOR_FLIGHTRED



end Function