I've been trying to extract data from an XML file, with some success, but there is still one problem I have not been able to resolve. Below is a portion of the XML file, followed by my code to create a table (called "Line") from it.
My code does get the six records, correctly getting the attributes for "@name" and "@type". However, I've been unable to guess what to use when setting .XMLName for the field to extract the other values that appear (229.99, -23.00, 206.99, 29.14, 0.00, and 236.13, respectively).
See the first call to my proc AddXMLField below --- I don't know what to use for the ?????s. I tried "..\Line", but this just gives me the first value, 229.99, for each record.
<Total>
<Line type="Subtotal" name="Subtotal">229.99</Line>
<Line type="Coupon" name="Coupon discount (fallshow)">-23.00</Line>
<Line type="Subtotal" name="Subtotal">206.99</Line>
<Line type="Shipping" name="Shipping">29.14</Line>
<Line type="Tax" name="Tax">0.00</Line>
<Line type="Total" name="Total">236.13</Line>
</Total>
oTable = SetupXMLTable( "Order/Total/Line", "Line")
AddXMLField( oTable, "??????", "line", "C", 40)
AddXMLField( oTable, "@name", "_name", "C", 40)
AddXMLField( oTable, "@type", "_type", "C", 10)
Procedure SetupXMLTable( lcName, lcAlias)
Local oTable
oTable = Createobject("XMLTable")
oTable.XMLName = Strconv(lcName, 5)
oTable.XMLNameIsXpath = .T.
oTable.Alias = lcAlias
If Used(lcAlias)
Use In (lcAlias)
Endif
Return oTable
Endproc
Procedure AddXMLField( oTable, lcXMLName, lcAlias, lcDataType, lnMaxLength, lnFractionDigits)
Local oField
oField = Createobject("XMLField")
oField.XMLName = Strconv( lcXMLName, 5)
oField.XMLNameIsXpath = .T.
oField.Alias = Evl( lcAlias, lcXMLName)
oField.DataType = lcDataType
oField.MaxLength = lnMaxLength
If Not Empty( lnFractionDigits)
oField.FractionDigits = lnFractionDigits
Endif
oTable.Fields.Add(oField, oField.XMLName)
Return oTable
Endproc
Thanks in advance
Jim Nelson
Newbury Park, CA