Wednesday, December 16, 2009

XML elementa nolasīšana ar VB palīdzību

Šoreiz savajadzējās uztaisīt funkciju, ar kuras palīdzību varam nolasīt konkrēta XML taga vērtību.

Nu tad te nu viņa arīdzan ir uzcepta:


Private Function RetrieveXML_TagValue(filePath As String, TagElementName As String, Optional ItemIndex As Integer = 0) As String
' Function returns Tag element value from XML file
' If ItemIndex is empty, then function returns first tag element

Dim xmlDoc As Object
Set xmlDoc = CreateObject("microsoft.xmldom")

xmlDoc.async = "false"
xmlDoc.Load (filePath)
TagElementName = UCase(TagElementName)

RetrieveXML_TagValue = xmlDoc.getElementsByTagName("" & TagElementName & "").Item("" & ItemIndex & "").nodeTypedValue

End Function

No comments: