将XML字符串转换为VFP表时出现问题,应该如何解决呢?
通过VFP从远程的web services里取得并返回了一个XML字符串,要将此字符串转换成VFP表,却实现不了,
请高手指点,谢谢!
我的代码是这样的:
PUBLIC cxml as String
thisform.setlcxmlstring()&&字符串赋值
LOCAL oXMLAdapter as XMLAdapter
oXMLAdapter = NEWOBJECT('XMLAdapter')
oXMLadapter.LoadXML(cXML,.f.)
*oXMLAdapter.tables(1).tocursor()
FOR nloop =1 TO oXMLadapter.tables.count
atable[nloop]=STRCONV(oXMLAdapter.tables(nloop).xmlname,6)
oXMLAdapter.tables(nloop).tocursor()
SELECT atable[nloop]
ctemp='c:\temp\td'+atable[nloop]
COPY TO &ctemp
endfor
RELEASE oxmladapter
运行之后,没有想要的表数据:(,请帮忙...
thisform.setlcxmlstring():
TEXT TO cxml noshow
<?xml version="1.0" encoding="UTF-8"?>
<XML_PriceAvailability_Response>
<Header>
<TransSetIDCode>846REC</TransSetIDCode>
<TransControlID/>
<ResponseVersion>1.4</ResponseVersion></Header>
<Detail>
<LineInfo>
<RefIDQual1>VP</RefIDQual1>
<RefID1>296460</RefID1>
<RefIDQual2>MG</RefIDQual2>
<RefID2>KTC3088/64</RefID2>
<RefIDQual4>UP</RefIDQual4>
<RefID4>740617030693</RefID4>
<ProductDesc>64MB COMPAQ PRESARIO </ProductDesc>
<PriceIDCode1>CON</PriceIDCode1>
<UnitPrice1>$27.77</UnitPrice1>
<PriceIDCode2>MSR</PriceIDCode2>
<UnitPrice2>$0.00</UnitPrice2>
<RequiredEndUserInfo>N</RequiredEndUserInfo>
<RequiredLicenseInfo>N</RequiredLicenseInfo>
<ProductWeight>0.200</ProductWeight>
<ItemStatus>DIS-VN</ItemStatus>
<WhseInfo>
<IDCode>FL & EXPORT ONLY</IDCode>
<WhseCode>A1</WhseCode>
<Qty>0</Qty></WhseInfo>
<WhseInfo>
<IDCode>SUWANEE, GA</IDCode>
<WhseCode>A2</WhseCode>
<Qty>0</Qty></WhseInfo>
<WhseInfo>
<IDCode>SWEDESBORO, NJ</IDCode>
<WhseCode>A3</WhseCode>
<Qty>0</Qty></WhseInfo>
<WhseInfo>
<IDCode>SOUTH BEND, IN</IDCode>
<WhseCode>A4</WhseCode>
<Qty>0</Qty></WhseInfo>
<WhseInfo>
<IDCode>FT WORTH, TX</IDCode>
<WhseCode>A5</WhseCode>
<Qty>0</Qty></WhseInfo>
<WhseInfo>
<IDCode>FONTANA, CA</IDCode>
<WhseCode>A6</WhseCode>
<Qty>0</Qty></WhseInfo></LineInfo>
<LineInfo>
<RefIDQual1>VP</RefIDQual1>
<RefID1>180054</RefID1>
<ErrorInfo>
<RefIDQual3>1Q</RefIDQual3>
<RefID3>0</RefID3>
<ErrorDesc>The requested item was not found in our product database</ErrorDesc></ErrorInfo></LineInfo></Detail>
<Summary>
<NbrOfSegments>12</NbrOfSegments></Summary></XML_PriceAvailability_Response>
ENDTEXT
------解决方案--------------------
就是对字符串查找,然后再写入DBF中。
请参考:
http://blog.csdn.net/apple_8180/archive/2007/11/15/1886244.aspx
这个就是从网络得到一个标准的XML,但VFP不能够直接用XMLTOCURSOR转入,就需要一点一点查找,提取,再保存。