Le code ObjectPAL suivant démontre comme utiliser Microsoft XML depuis Paradox pour parcourir l'intégralité d'un document XML au moyen de l'API DOM XML.
Une présentation beaucoup plus complète sur Paradox et XML a été donnée lors de la Convention Internationale Paradox 2003, et est présentée sur un site dédié: Paradox et XML
var
ss string
doingAttributes logical
endvar
;----------------------------------------------------------------
proc doChildrenOf(var Parentnode OleAuto)
var
cAttributeNodes,cNodes oleAuto
ThisNode,ThisAttributeNode oleAuto
endvar
try
cnodes = Parentnode.ChildNodes ; get the list of child nodes
for i from 1 to cnodes^length
ThisNode = cnodes.nextNode
message(ThisNode^nodeValue)
nodeType = ThisNode^nodeType
switch
case nodeType = 1: ; ELEMENT
ss = ss + "\r\n"
ss = ss + ThisNode^tagName
;-- now get the list of attributes for this Element node
cAttributeNodes = ThisNode.Attributes
for j from 1 to cAttributeNodes^length
ThisAttributeNode = cAttributeNodes^NextNode
ss = ss + " (" + ThisAttributeNode^Name
doingAttributes = TRUE
doChildrenOf (ThisAttributeNode)
ThisAttributeNode.Close ()
endfor
cAttributeNodes.Close ()
doingAttributes = FALSE
doChildrenOf (ThisNode)
case NodeType = 2: ; ATTRIBUTE
doChildrenOf (ThisNode)
case NodeType = 3: ; TEXT
ss = ss + " = " + ThisNode^nodeValue
;-- if doing an attribute value,
; put in the closing parenthesis
if doingAttributes then
ss = ss + ")"
endif
case NodeType = 4: ; CDATA_SECTION
case NodeType = 5: ; ENTITY_REFERENCE
doChildrenOf (ThisNode)
case NodeType = 6: ; ENTITY
doChildrenOf (ThisNode)
case NodeType = 7: ; PROCESSING_INSTRUCTION
case NodeType = 8: ; COMMENT
case NodeType = 9: ; DOCUMENT
case NodeType = 10: ; DOCUMENT_TYPE
doChildrenOf (ThisNode)
case NodeType = 11: ; DOCUMENT_FRAGMENT
doChildrenOf (ThisNode)
case NodeType = 12: ; NOTATION
otherwise:
msgStop ("Unknown Node Type: " + string(NodeType),"")
endswitch
endfor
ThisNode.close ()
cnodes.close ()
onfail
errorShow ()
endtry
endproc
;----------------------------------------------------------------
method pushButton(var eventInfo Event)
const
URL = "http://www.osinet.fr/xlink/xlinkxsa.xml"
endConst
var
oDOM OleAuto
doc OleAuto
endVar
if NOT oDOM.open ("Microsoft.XMLDOM") then
errorShow()
return
endif
oDOM.async = False
if NOT oDOM.load (URL) then
errorShow ()
return
endif
doc = oDOM^documentElement
ss = ""
doingAttributes = FALSE
doChildrenOf (doc)
MyMemo.Text = ss
doc.Close ()
oDom.Close ()
endMethod
Ce code doit être placé dans un conteneur adéquat, typiquement une fiche ou une page contenant la fiche. La méthode à appeler directement est pushButton, à placer typiquement sur un bouton, et la méthode récursive doChildrenOf réalise le travail réel.
Tip fourni par Frédéric G. MARAND et John CORKILL, adapté et publié avec autorisation des auteurs. Tous droits réservés.