在Livecode中,我使用XML从数据库中提取信息,并使用重复功能对其进行组织。因此,对于每个节点,都有信息,如照片,姓名,年龄等。
然而,照片是从XML中读取的照片的URL链接。有没有办法自动加载此URL并使图片显示在其后的节点中?
on preOpenStack
put url "http://www.petango.com/webservices/wsadoption.asmx/AdoptableSearch?authkey=XXXXXXXX&speciesID=&sex=&ageGroup=&location=&site=&onHold=&orderBy=&primaryBreed=&secondaryBreed=&specialNeeds=&noDogs=&noCats=&noKids=&stageID=" into tURL
put revCreateXMLTree( tURL, true, true, false) into tInfo
put revXMLChildNames( tInfo, "ArrayOfXmlNode", return, "XmlNode", true) into tChildren
repeat for each line tChild in tChildren
add 1 to x
put revXMLChildNames( tInfo, "ArrayOfXmlNode/"&tChild&backslash, return, "adoptableSearch", true) into tAdoptable
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Photo") into tData
put "Name: " & revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Name") & return after tData
put return after tData
put return after tData
end repeat
put tData & return after tOutput
set the text of field "tData" to tOutput
end preOpenStack
答案 0 :(得分:0)
您写的是XML节点返回照片的URL,但您不会写出这是哪个节点。假设
revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Photo")
返回网址。将URL放入变量并使用它来设置图像对象的文本:
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Photo") into myUrl
put url myUrl into myPictureData
if the result is empty then
set the text of img 1 to myPictureData
else
beep
answer error "Can't load picture."
end if
答案 1 :(得分:0)
很抱歉在Marks出色的答案之后占据了主线。但我通常只是为图像设置文件名:
repeat for each line tChild in tChildren
add 1 to x
...
put revXMLNodeContents( tInfo, "ArrayOfXmlNode/"&tChild&"/"&tAdoptable&"/Photo") into myUrl
create image ("image" && x)
put it into tImageID
set the filename of tImageID to myURL
...
end repeat
这不会检查图像是否正确加载,但是因为您无法获得任何图像,这是一个简单的解决方案。