Sub XMLRead (xmlFile, tag, attribute)
xmlContent = ReadFile (xmlFile)
If (length (xmlContent) = 0)
Return ("exit")
Exitsub
Endif
#Parse the tag string into an array
i = 1
ForEach tagTemp in split (tag, ">", TRUE)
If (charAt (tagTemp, 1) eq "<")
tagTemp = SubStr (tagTemp, 2)
Endif
If (tagTemp ne "")
tagArray [i] = tagTemp
i + = 1
Endif
EndforEach
#Find the tag's location in the file. If it doesn't exist, search for it in lowercase.
ForEach tag in array (tagArray)
tempLocation = Find (xmlContent, "<" & tag, tagLocation)
If (tempLocation = 0)
tagLocation = Find (xmlContent, "<" & ToLower (tag), tagLocation)
Else
tagLocation = tempLocation
Endif
#If an attribute was specified, make sure that it was found; otherwise, continue searching.
If (attribute ne "" AND tag ne "root")
endTagLocation = Find (xmlContent, ">", tagLocation + 1)
tagContent = SubStr (xmlContent, tagLocation, endTagLocation - tagLocation)
attributeLocation = Find (tagContent, attribute & "=" "")
While (attributeLocation = 0 AND endTagLocation> = length (xmlContent) - 5)
tagLocation = Find (xmlContent, "<" & tag, endTagLocation)
If (tagLocation = 0)
tagLocation = Find (xmlContent, "<" & ToLower (tag), endTagLocation)
Endif
endTagLocation = Find (xmlContent, ">", tagLocation + 1)
tagContent = SubStr (xmlContent, tagLocation, endTagLocation - tagLocation)
attributeLocation = Find (tagContent, attribute & "=" "")
Endwhile
Endif
EndForEach
Clear (tagArray)
#If an attribute was not specificed, set the file pointer to the tag ...
If (attribute eq "")
valueLocation = Find (xmlContent, ">", tagLocation) + 1
valueLocationEnd = Find (xmlContent, "<", valueLocation)
value = SubStr (xmlContent, valueLocation, valueLocationEnd - valueLocation)
# ... else set the file pointer to the attribute
Else
#Find the attribute's location in the file. If it doesn't exist, search for it in lowercase.
tempValueLocation = Find (xmlContent, attribute & "=" "", tagLocation)
If (tempValueLocation = 0)
valueLocation = Find (xmlContent, ToLower (attribute) & "=" "", tagLocation)
Else
valueLocation = tempValueLocation
Endif
#Find and read the value from the attribute
If (valueLocation <> 0)
valueLocation + = length (attribute) + 2
Endif
valueLocationEnd = Find (xmlContent, "" "", valueLocation)
If (valueLocationEnd = valueLocation)
value = ""
Else
value = SubStr (xmlContent, valueLocation, valueLocationEnd - valueLocation)
Endif
Endif
Return (value)
Endsub