也许这里有一些了解 FANUC KAREL 的人。我必须创建一个 XML 解析器来获取电报的特定部分。
我从 FANUC 模板代码开始,但目前我没有得到任何结果。没有什么。
在这里你可以看到消息,我必须解析:
<?xml version="1.0" ?>
<message><name>Run.Locate.Ok</name><job>1</job><match>1</match><matches>1</matches><x>90.735872311523</x><y>-5.0591040552784</y><z>0</z><rx>0</rx><ry>0</ry><rz>166.37113177833</rz><px>90.735872311523</px><py>-5.0591040552784</py><pz>0</pz><prx>0</prx><pry>0</pry><prz>166.37113177833</prz><scale>1.0</scale><score>97.627884149551</score><time>134</time><exposure>1</exposure><identified>1</identified></message>
在这里你可以看到我当前的 KAREL 来源:
PROGRAM xmlparse
%NOLOCKGROUP
%NOPAUSESHFT
%NOPAUSE = ERROR + COMMAND + TPENABLE
%NOABORT = ERROR + COMMAND
%ENVIRONMENT xml
%include klerxmlf
CONST
MYXML_CONST = 3
TYPE
xmlstrct_t = STRUCTURE
first : integer
second : real
third : boolean
fourth : string[20]
ENDSTRUCTURE
-- Local Vars
VAR
xml_result : file
status : INTEGER
tag_name : string[32]
attrnames : array[32] of string[32]
attrvalues : array[32] of string[64]
text : array[32] of String[128]
xmlstrct : xmlstrct_t
tag_ident : integer
textdone : boolean
func_code : integer
text_idx : integer
numattr : integer
done : boolean
startdata : boolean
xmlp_done : boolean
Routine xml_parse:boolean
BEGIN
-- Parse XML Data
SET_FILE_ATR(xml_result, ATR_XML)
CLR_IO_STAT(xml_result)
WRITE TPDISPLAY('XML_Start',CR)
OPEN FILE xml_result('RO','MC:\result.xml')
WRITE TPDISPLAY('File OK',CR)
status = IO_STATUS(xml_result)
WRITE TPDISPLAY('Status 1',CR)
IF (status <> 0) THEN
POST_ERR(status, '', 0, 0)
abort
ENDIF
WRITE TPDISPLAY('Status 2',CR)
xml_addtag (xml_result, 'xmlstrct_t', 32, FALSE, MYXML_CONST, status)
WRITE TPDISPLAY('Status 3',CR)
textdone = TRUE
done = FALSE
startdata = FALSE
while (done = FALSE) DO
xml_scan(xml_result,'message',tag_ident,func_code,status)
WRITE TPDISPLAY('Status 4',CR)
if (status = 0) THEN
done = TRUE
ENDIF
IF (status = XML_FUNCTION) THEN
Status = 0
SELECT tag_ident of
Case (MYXML_CONST) :
SELECT func_code of
Case (XML_START) :
text_idx = 1
xml_setvar (xml_result, 'message', 'xmlstrct', status)
xml_getdata(xml_result, numattr, attrnames, attrvalues, text[text_idx], textdone, status)
Case (XML_END) :
IF (startdata = TRUE) THEN
startdata = FALSE
ELSE
text_idx = 1
xml_setvar (xml_result, 'message', 'xmlstrct', status)
xml_getdata(xml_result, numattr, attrnames, attrvalues, text[text_idx], textdone, status)
ENDIF
Case (XML_TXCONT) :
text_idx = text_idx + 1
xml_getdata (xml_result, numattr, attrnames, attrvalues, text[text_idx], textdone, status)
ELSE:
ENDSELECT
ELSE:
ENDSELECT
ELSE
IF (status <> XML_SCANLIM) THEN
POST_ERR(status, '', 0, 0)
done = TRUE
ENDIF
ENDIF
ENDWHILE
WRITE TPDISPLAY('Status 5',CR)
xml_remtag(xml_result, 'xmlstrct_t', status)
close file xml_result
status = IO_STATUS(xml_result)
IF (status <> 0) THEN
POST_ERR(status, '', 0, 0)
xmlp_done = FALSE
ELSE
xmlp_done = TRUE
ENDIF
WRITE TPDISPLAY('File Closed 3',CR)
RETURN (xmlp_done)
END xml_parse
Begin
END xmlparse
我需要的是单独的标签内容,比如位置。
谁能给我一些大脑输入?
谢谢!