Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 10:16:27 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: FBSL - XML Class  (Read 3722 times)

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
FBSL - XML Class
« on: February 07, 2006, 05:02:59 AM »
Hello,

Here's an XML Class to manipulate XML files under windows using XML DOM COM interface...

$Apptype CONSOLE
#Option Explicit


' ---------------------------------------------
' // Sample Test
' ---------------------------------------------
Dim %xml
CXml.Init()
xml = CXml.LoadXml( ".\Album.xml" )
    If CXml.myStrerr = "" Then
        CXml.GetNodeListCount( "title" )
        ? "The 1st 'title' of the 1st 'Album' tag is :", CrLf, CXml.GetNodeListItem(1), CrLf
        CXml.GetNodeListCount( "artist" )
        ? "Its 'artist' is :", CrLf, CXml.GetNodeListItem(1), CrLf       
    End If
CXml.Terminate()
Pause


' ---------------------------------------------
'// XML Class
' ---------------------------------------------
#region XML Class by Gerome GUILLEMIN
Class CXml()
Dim %myObj, %theNodeList, $myStrerr

    Sub Init()
        ComWarnings(False)
        myObj = CreateObject( "Microsoft.XMLDOM" )
        PutValue( myObj, ".async(%b)", False )
        PutValue( myObj, "ValidateOnParse = %b", True )
    End Sub

    Function %LoadXml( Byref $szXmlFileName ) 'As Object
        If myObj = False Then Return False
        If FileExist( szXmlFileName ) = False Then
            myStrerr = "File does not exist!"
            Return False
        End If
        CallMethod( myObj, ".Load(%s)", szXmlFileName )
        If GetValue( "%d", myObj, ".parseError.errorCode" ) <> False Then
            myStrerr = "Error at line : " & GetValue( "%d", myObj, ".parseError.line" ) & _
            GetValue( "%s", myObj, ".parseError.srcText" )
            Return False
        End If
        Return myObj
    End Function

    Function %GetNodeListCount( Byref $szNodeName )
        If myObj = 0 Then Return False
        If theNodeList <> False Then ReleaseObject(theNodeList)
        Set theNodeList = GetValue( "%o", myObj, ".getElementsByTagName(%s)", szNodeName )
        If theNodeList = False Then
            ReleaseObject(theNodeList)
            Return False
        Else
            Return GetValue( "%d", theNodeList, ".Length" )
        End If
    End Function

    Function $GetNodeListItem( Byref %theiTem )
        If myObj = 0 Then Return ""
        Return GetValue( "%s", theNodeList, ".item(%d).text", theiTem-1 )
    End Function

    Sub Terminate()
        If theNodeList <> False Then ReleaseObject(theNodeList)
        If myObj <> False Then ReleaseObject(myObj)
        myStrerr = ""
        ComWarnings(True)
    End Sub

End Class
' ---------------------------------------------
#endregion
' ---------------------------------------------

To test this class, you need the following XML file (saved as 'album.xml') :
<?xml version="1.0"?>
<Albums>
   <Album ref="CD142" category="Folk">
      <title>Boil The Breakfast Early</title>
      <artist>The Chieftains</artist>
   </Album>
   <Album ref="CD720" category="Pop">
      <title>Come On Over</title>
      <artist>Shania Twain</artist>
   </Album>
   <Album ref="CD024" category="Country">
      <title>Red Dirt Girl</title>
      <artist>Emmylou Harris</artist>
   </Album>
</Albums>

Enjoy FBSL :)
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)
« Last Edit: February 07, 2006, 05:39:18 AM by mouser »

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: XML Class
« Reply #1 on: February 07, 2006, 05:09:02 AM »
i'm going to move this to coders corner.

Gerome

  • Charter Honorary Member
  • Joined in 2006
  • ***
  • Posts: 154
    • View Profile
    • Get my Freestyle Basic Script Language + compiler!
    • Donate to Member
Re: XML Class
« Reply #2 on: February 07, 2006, 05:18:46 AM »
Hi,

i'm going to move this to coders corner.

Ok, thanks :)
Don't forget to test all of my samples with my online compiler :)
http://gedd123.free.fr/studio <- Fbsl Online compiler!
Yours,
(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
http://www.fbsl.net [FBSL Author]
http://gedd123.free.fr/FBSLv3.zip [FBSL Help file]
(¯`·._.·[If you need help... just ask]·._.·´¯)