><?xml version="1.0" encoding="ISO-8859-1"?> ><invoice> > <number>11009</number> > <date>20020801</date> > <rows> > <row> > <item>80686001508</item> > <quantity>2</quantity> > </row> > <row> > <item>2136861443</item> > <quantity>4.5</quantity> > </row> > </rows> ></invoice> >>
source = CreateObject('MSXML.Domdocument') source.loadXml(FileToStr('source.xml')) stylesheet = CreateObject('MSXML.Domdocument') stylesheet.loadXML(FileToStr('invoice.xsl')) result = CreateObject('MSXML.Domdocument') result.validateOnParse = .t. source.transformNodeToObject(stylesheet, @result) XMLToCursor(result.xml, 'Invoice') BrowseThis assumes that source.xml is file with the above xml structure and with the invoice data. Invoice.xsl is gile with the following content:
<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" standalone="yes"/> <!-- this replaces root tag with VFPData which is required from CursorToXML to work properly --> <xsl:template match="/"> <xsl:element name="VFPData"> <xsl:apply-templates/> </xsl:element> </xsl:template> <!-- this will denormalize XML data --> <xsl:template match="/invoice/rows/*"> <xsl:element name="invoice"> <xsl:element name="number"><xsl:value-of select="../../number"/></xsl:element> <xsl:element name="date"><xsl:value-of select="../../date"/></xsl:element> <xsl:element name="item"><xsl:value-of select="item"/></xsl:element> <xsl:element name="quantity"><xsl:value-of select="quantity"/></xsl:element> </xsl:element> </xsl:template> <!-- to ommit nodes data --> <xsl:template match="text()"> </xsl:template> <!-- to work over every node --> <xsl:template match="*"> <xsl:apply-templates/> </xsl:template> </xsl:stylesheet>According to me it is the fastest and simplest approach.
Make solutions, not programs!