'**-- custom class that holds XML of one field
'**-- XML Sample: field_value
'**-- for use in XMLRecordset
class XMLField
private moElmntDoc
private sub Class_Initialize
set moElmntDoc = nothing
end sub
private sub Class_Terminate
set moElmntDoc = nothing
end sub
public property let XML(sXML)
dim oDom
set oDom = CreateObject("MSXML.DOMDocument")
oDom.loadXML sXML
if oDom.xml <> "" then
set moElmntDoc = oDom.documentElement
end if
set oDom = nothing
end property
public property get Value()
if not moElmntDoc is nothing then
Value = moElmntDoc.text
end if
end property
end class
'**-- custom class that holds XML of the recordset
'**-- XML Sample: field_value
'**-- for use as Recordset
'**-- Sample of using this class:
''''--------------------------------''''
' dim oXmlRs
' dim sRes
'
' set oXmlRs = new XMLRecordset
' oXmlRs.XML = sXml
'
' while not oXmlRs.EOF
' sRes = sRes & oXmlRs.Fields("field_name").Value
' oXmlRs.MoveNext
' wend
''''--------------------------------''''
class XMLRecordset
private moElmntDoc
private moElmntRow
private sub Class_Initialize
set moElmntDoc = nothing
set moElmntRow = nothing
end sub
private sub Class_Terminate
set moElmntDoc = nothing
set moElmntRow = nothing
end sub
public property let XML(sXML)
dim oDom
set oDom = CreateObject("MSXML.DOMDocument")
oDom.loadXML sXML
if oDom.xml <> "" then
set moElmntDoc = oDom.documentElement
set moElmntRow = moElmntDoc.firstChild
end if
set oDom = nothing
end property
public property get EOF()
if moElmntRow is nothing then
EOF = true
else
EOF = false
end if
end property
public property get Fields(Index)
dim oElmnt
dim oElmntFld
dim oXMLFld
set oXMLFld = nothing
set oElmntFld = nothing
if not moElmntRow is nothing then
if LCase(TypeName(Index)) = "string" then
'**-- get field by field Name
for each oElmnt in moElmntRow.childNodes
if LCase(oElmnt.getAttribute("Name")) = LCase(Index) then
set oElmntFld = oElmnt
exit for
end if
next
elseif LCase(TypeName(Index)) = "integer" then
'**-- get field by Index
set oElmntFld = moElmntRow.childNodes(Index)
end if
if not oElmntFld is nothing then
set oXMLFld = new XMLField
oXMLFld.XML = oElmntFld.xml
end if
end if
set Fields = oXMLFld
set oElmnt = nothing
set oElmntFld = nothing
set oXMLFld = nothing
end property
public function MoveNext()
if not moElmntRow is nothing then
set moElmntRow = moElmntRow.nextSibling
end if
end function
public function MoveFirst()
if not moElmntDoc is nothing then
set moElmntRow = moElmntDoc.firstChild
end if
end function
public function Remove(Index)
dim oElmnt
dim oElmntFld
set oElmntFld = nothing
if not moElmntRow is nothing then
if LCase(TypeName(Index)) = "string" then
'**-- get field by field Name
for each oElmnt in moElmntRow.childNodes
if LCase(oElmnt.getAttribute("Name")) = LCase(Index) then
set oElmntFld = oElmnt
exit for
end if
next
elseif LCase(TypeName(Index)) = "integer" then
'**-- get field by Index
set oElmntFld = moElmntRow.childNodes(Index)
end if
if not oElmntFld is nothing then
oElmntFld.parentNode.removeChild oElmntFld
Remove = true
end if
end if
set oElmnt = nothing
set oElmntFld = nothing
end function
end class