SET MEMOWIDTH TO 150 * use XPath scripting to get FOREIGN key from the parent CLOSE DATABASES all CLEAR LOCAL oXA as XMLAdapter, oBar as XMLTable oXA=CREATEOBJECT("XMLAdapter") TEXT TO cXML NOSHOW <?xml version = "1.0" encoding="Windows-1252" standalone="yes"?> <VFPDataSet> <xsd:schema id="VFPDataSet" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:element name="VFPDataSet" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="foo" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="f1" type="xsd:int"/> <xsd:element name="BAR" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="f2"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="5"/> </xsd:restriction> </xsd:simpleType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:choice> <xsd:anyAttribute namespace="http://www.w3.org/XML/1998/namespace" processContents="lax"/> </xsd:complexType> </xsd:element> </xsd:schema> <foo> <f1>1</f1> <BAR> <f2>1</f2> </BAR> <BAR> <f2>11</f2> </BAR> <BAR> <f2>111</f2> </BAR> <BAR> <f2>1111</f2> </BAR> <BAR> <f2>11111</f2> </BAR> </foo> <foo> <f1>2</f1> <BAR> <f2>2</f2> </BAR> <BAR> <f2>22</f2> </BAR> <BAR> <f2>222</f2> </BAR> </foo> <foo> <f1>3</f1> <BAR> <f2>333</f2> </BAR> <BAR> <f2>3333</f2> </BAR> <BAR> <f2>33333</f2> </BAR> </foo> </VFPDataSet> ENDTEXT oXA.LoadXML(cXML,.F.) oBar=oXA.Tables(STRCONV("BAR",5)) AddXmlField(oBar,"parent::foo/f1",.F.,"f1","I",-1,.T.) AdapterToCursors(oXA) FUNCTION AdapterToCursors(oXA as XMLAdapter) FOR EACH oXT IN oXA.Tables oXT.ToCursor() SELECT (oXT.Alias) ? ALIAS() LIST NEXT endfunc FUNCTION AddXmlField(oXT,cXMLName,lAttribute,cAlias,cDataType,nMaxLength,lXPath) oXF=CREATEOBJECT("XMLField") IF VERSION(5)>=900 oXF.XMLNameIsXPath=lXPath ENDIF oXF.XMLName=STRCONV(cXMLName,5) oXF.IsAttribute= lAttribute oXF.Alias=cAlias oXF.DataType=cDataType oXF.MaxLength=nMaxLength oXF.IsNULL=.T. oXT.Fields.Add(oXF,oXF.XMLName) RETURN oXF ENDFUNCOutput:
BAR Record# F2 F1 1 1 1 2 11 1 3 111 1 4 1111 1 5 11111 1 6 2 2 7 22 2 8 222 2 9 333 3 10 3333 3 11 33333 3 FOO Record# F1 1 1 2 2 3 3Thanks,