Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
XMLField question
Message
From
28/09/2006 18:13:38
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
XML, XSD
Title:
XMLField question
Miscellaneous
Thread ID:
01158009
Message ID:
01158009
Views:
86
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")
	* all XMLName properties must be Unicode
	oTable.XMLName = Strconv(lcName, 5)
	oTable.XMLNameIsXpath = .T.
	* the cursor's alias
	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
Next
Reply
Map
View

Click here to load this message in the networking platform