Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 253732 - Last Review: July 13, 2004 - Revision: 2.4
How To Use FoxPro and MSXML to Return Information About an XML Document
This article was previously published under Q253732
This simple example shows how to return values from an XML document using Microsoft Visual FoxPro.
This example uses the Microsoft XML (MSXML) parser to move data from an XML document to a FoxPro table. The parser is available at:
The following code creates the Microsoft MSXML ActiveX object to accesses information contained in an XML document and displays it:
- Install the MSXML parser.
- Create the XML document by copying the sample XML code below to a text file and name the file with the extension .
- Create a FoxPro program file with the following code and run the program:
PUBLIC oXML
oXML=CREATEOBJECT('msxml.domdocument') && This creates the parser object
oXML.LOAD(GETFILE('xml')) && This gets and loads the XML document.
*** Select the XML document created from the XML code below.
*** The following gives the basename / RootElemant of the XML document
? oXml.DocumentElement.Basename
*** The following gives the number of nodes (or records)
? oXML.documentelement.childnodes.LENGTH
*** REMEMBER that the object model is in base zero.
*** Therefore use the following in looping expressions
? oXML.documentelement.childnodes.LENGTH - 1
*** The following returns the number of child nodes contained under the first Item
*** This is useful for looping through a childes elements
*** FOR ichild = 0 TO oXML.documentelement.childnodes.ITEM(0).childnodes.LENGTH - 1
? oXML.documentelement.childnodes.ITEM(0).childnodes.LENGTH - 1
*** The following returns the nodename of the childnode
? oxml.documentelement.childnodes.item(0).childnodes(0).nodename
*** The following returns the data contained in the childnode
? oXML.documentelement.childnodes.ITEM(0).childnodes(0).TEXT
*** Returns a string of all the data contained in the second child / record
? oXml.documentelement.childnodes.item(1).nodetypedvalue
XML Code
<orders_table>
<orders>
<order_id> 10040</order_id>
<cust_id>WHITC </cust_id>
<emp_id> 3</emp_id>
<to_name>White Clover Markets</to_name>
<to_address>1029 - 12th Ave. S.</to_address>
<to_city>Bellevue</to_city>
<to_region>WA</to_region>
<postalcode>98124</postalcode>
<to_country>USA</to_country>
<ship_count>USA</ship_count>
<ship_via> 3</ship_via>
<order_date>09/09/93</order_date>
<order_amt>$1,991.00</order_amt>
<order_dsc>10</order_dsc>
<order_net>$1,842.88</order_net>
<require_by>10/07/93</require_by>
<shipped_on>09/18/93</shipped_on>
<freight>$51.88</freight>
</orders>
<orders>
<order_id> 10095</order_id>
<cust_id>LAZYK </cust_id>
<emp_id> 3</emp_id>
<to_name>Lazy K Kountry Store</to_name>
<to_address>12 Orchestra Terrace</to_address>
<to_city>Walla Walla</to_city>
<to_region>WA</to_region>
<postalcode>99362</postalcode>
<to_country>USA</to_country>
<ship_count>USA</ship_count>
<ship_via> 3</ship_via>
<order_date>12/10/93</order_date>
<order_amt>$530.00</order_amt>
<order_dsc>10</order_dsc>
<order_net>$479.58</order_net>
<require_by>01/07/94</require_by>
<shipped_on>12/11/93</shipped_on>
<freight>$2.58</freight>
</orders>
</orders_table>
For additional information on XML, click the article number below
to view the article in the Microsoft Knowledge Base:
191758Â
(http://kbalertz.com/Feedback.aspx?kbNumber=191758/EN-US/
)
Convert FoxPro Cursor into XML Data Format
253713Â
(http://kbalertz.com/Feedback.aspx?kbNumber=253713/EN-US/
)
Move Data From an XML Document into a FoxPro Table
For more information about XML, see the following Web sites:
APPLIES TO
- Microsoft Visual FoxPro 6.0 Professional Edition
- Microsoft XML Parser 2.5
- Microsoft XML Parser 2.6
- Microsoft XML Parser 3.0
| kbhowto kbmisctools KB253732 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate