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