我正在尝试使用TCP服务器客户端API从eye tracker实现XML字符串的实时解析,用于: 1) 以.csv或其他格式存储它们以供脱机分析。 2) 在屏幕上显示凝视坐标
xml字符串的一个小示例如下所示:
<REC FPOGX="0.68449" FPOGY="0.81953" FPOGS="1789.73828" FPOGD="0.77747" FPOGID="4894" FPOGV="1" CX="0.95781" CY="0.39074" CS="0" />
<REC FPOGX="0.68449" FPOGY="0.81953" FPOGS="1789.73828" FPOGD="0.77747" FPOGID="4894" FPOGV="1" CX="0.95781" CY="0.39074" CS="0" />
<REC FPOGX="0.68449" FPOGY="0.81953" FPOGS="1789.73828" FPOGD="0.77747" FPOGID="4894" FPOGV="1" CX="0.95781" CY="0.39074" CS="0" />
<REC FPOGX="0.68405" FPOGY="0.81942" FPOGS="1789.73828" FPOGD="0.80640" FPOGID="4894" FPOGV="1" CX="0.95781" CY="0.39074" CS="0" />
<REC FPOGX="0.68405" FPOGY="0.81942" FPOGS="1789.73828" FPOGD="0.80640" FPOGID="4894" FPOGV="1" CX="0.95781" CY="0.39074" CS="0" />
<REC FPOGX="0.68405" FPOGY="0.81942" FPOGS="1789.73828" FPOGD="0.80640" FPOGID="4894" FPOGV="1" CX="0.95781" CY="0.39074" CS="0" />
眼睛跟踪器每6.6毫秒发送一个样本(如上所示)。我所看到的大部分内容都是获取静态xml文件并进行解析。然而,在我的例子中,我想实时这样做,这样我就可以读取X,Y凝视坐标(例如FPOGX和FPOGY)并在屏幕上显示它们(为此,我将使用一个实验设计软件)。有什么办法吗
非常感谢
如果您将其作为xml字符串接收,只需对数据结构执行
ET.fromstring(<xml_string>).attrib
:输出:
对于csv部分,您可以使用这个
append_csv_dict
函数(我使用的标准函数):输出(data.csv):
下面的代码应该可以做到这一点:
您可以使用xml.etree.ElementTree模块处理字符串。输出将是字典
相关问题 更多 >
编程相关推荐