Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Newbie question on processing XML file
Message
De
01/12/2003 13:36:53
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
XML, XSD
Divers
Thread ID:
00854652
Message ID:
00854762
Vues:
39
Hi Dmitry.

And how would you suggest to handle the XML file if the structure would be more complicated,

I suppose that depends on what you want to do with the contents of the file. If you just want to process the data, you could create a little wrapper class along these lines (untested):
DEFINE CLASS VFPDomhandler AS Session OLEPUBLIC
  cVersion = 'MSXML2.DOMDOCUMENT.4.0'
  oXml = .NULL.

FUNCTION Init
  LOCAL llRetVal
  llRetVal = DODEFAULT()
  IF llRetVal
    *** instantiate the dom
    This.oXML = CREATEOBJECT( This.cVersion )
  ENDIF
  RETURN llRetVal
ENDFUNC

FUNCTION Parse( tcFile )
  WITH This.oXml
    .load( tcFile )
    This.ProcessNode( .DocumentElement )
  ENDWITH
ENDFUNC

FUNCTION processnode( tonode )
  #DEFINE NODE_INVALID	0	
  #DEFINE NODE_ELEMENT	1	
  #DEFINE NODE_ATTRIBUTE 2	
  #DEFINE NODE_TEXT 3	
  #DEFINE NODE_CDATA_SECTION 4	
  #DEFINE NODE_ENTITY_REFERENCE	5	
  #DEFINE NODE_PROCESSING_INSTRUCTION 7	
  #DEFINE NODE_COMMENT	8	
  #DEFINE NODE_DOCUMENT	9	
  #DEFINE NODE_DOCUMENT_TYPE 10	
  #DEFINE NODE_DOCUMENT_FRAGMENT 11	
  #DEFINE NODE_NOTATION	12	

  *** Next see if we have any attributes
  This.GetAttributes( toNode )

  *** if this is a text node, use it to do whatever you want
  IF toNode.NodeType = NODE_TEXT
    ? toNode.NodeValue
  ENDIF

  *** Process any kids
  IF toNode.HasChildNodes
    FOR EACH lochild in toNode.ChildNodes
      This.ProcessNode( loChild )
    ENDFOR
  ENDIF
ENDFUNC

FUNCTION GetAttributes( toNode )
  LOCAL loAttributes, lnAttributes, lnAttr
  loAttributes = toNode.Attributes
  IF VARTYPE( loAttributes ) = 'O'
    lnAttributes = loAttributes.Length - 1
    IF lnAttributes >= 0
      FOR lnAttr = 0 TO lnAttributes
	? loAttributes.Item[ lnAttr ].NodeName + [: ] + loAttributes.Item[ lnAttr ].NodeValue
      ENDFOR
    ENDIF
  ENDIF
ENDFUNC
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform