Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie question on processing XML file
Message
 
 
To
01/12/2003 13:36:53
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Miscellaneous
Thread ID:
00854652
Message ID:
00854848
Views:
26
Marcia,

Thank you very much for the example of the wrapper class.

>
>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
>
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform