XMLRead

Returns array of values by an XML expression from XML file.
Xmlfilepath is the absolute path to an XML file.
expression is a valid node path or xml query in the specified XML file.

strXMLPath = Server.Mappath("/aspemporium/examples/xmlcatalog/database.xml")
strXMLExpression    = "/CATALOG/MOVIE[RUNNINGTIME $gt$ 100]/RATING | /CATALOG/MOVIE[RUNNINGTIME $gt$ 100]/TITLE"
a    = XMLRead( strXMLPath, strXMLExpression )
for i = 0 to ubound(a) - 1
    Response.Write a(i) & "
"
next

CodeFunctionName
What is this?

Public

Not Tested

Imported
Private Function XMLRead(byVal xmlfilepath, byVal expression)
    dim temp, item, tmp, objXML, tmpArray
    On Error Resume Next
    Set objXML = Server.CreateObject("Microsoft.XMLDOM")
    objXML.Load( xmlfilepath )
    If Err Then
        On Error GoTo 0
        Err.Raise 5140, "XMLRead Function", "Specified XML File Not Found."
        Err.Clear
        XMLRead = Null
        set objXML = Nothing
        Exit Function
    End If
    set temp = objXML.documentElement.selectnodes( expression )
    If Err Then
        On Error GoTo 0
        Err.Raise 5140, "XMLRead Function", "Expression argument produced an error."
        Err.Clear
        XMLRead = Null
        set objXML = Nothing
        Exit Function
    End If
    for each item in temp
        tmp = tmp & item.text & vbCrLf & "/" & vbCrLf
    next
    set temp = Nothing
    set objXML = Nothing
    tmpArray = Split( tmp, vbCrLf & "/" & vbCrLf )
    XMLRead = tmpArray
    On Error GoTo 0
End Function

byVal xmlfilepath, byVal expression

dim i, a, strXMLPath, strXMLExpression
strXMLPath        = Server.Mappath("/aspemporium/examples/xmlcatalog/database.xml")
strXMLExpression    = "/CATALOG/MOVIE[RUNNINGTIME $gt$ 100]/RATING | /CATALOG/MOVIE[RUNNINGTIME $gt$ 100]/TITLE"
a    = XMLRead( strXMLPath, strXMLExpression )
for i = 0 to ubound(a) - 1
    Response.Write a(i) & "<BR>"
next

Views 142

Downloads 47

CodeID
DB ID

ANmarAmdeen
604
Attachments
Revisions

v1.0

Sunday
November
26
2023