简体   繁体   English

在Python中解析XML的最快方法

[英]Fastest way to parse XML in Python

I'm trying to find the qickest way to parse sensor data from a smartphone for a realtime application. 我正在尝试找到从智能手机解析传感器数据的最快方法,以用于实时应用程序。 The Format looks like this: 格式如下所示:

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<NodeId>0</NodeId>
<Accelerometer>
    <Accelerometer1>-.1875240802764893</Accelerometer1>
    <Accelerometer2>4.6734819412231445</Accelerometer2>
    <Accelerometer3>8.312667846679688</Accelerometer3>
</Accelerometer>
<Gyroscope>
    <Gyroscope1>-0.10551923513412476</Gyroscope1>
    <Gyroscope2>0.009592439979314804</Gyroscope2>
    <Gyroscope3>0.019185146316885948</Gyroscope3>
</Gyroscope>
<Gravity>
    <Gravity1>-1.2976515293121338</Gravity1>
    <Gravity2>3.672762393951416</Gravity2>
    <Gravity3>9.003327369689941</Gravity3>
</Gravity>
<TimeStamp>1377767599250</TimeStamp>

The available sensor data might change depending on the phone. 可用的传感器数据可能会因手机而异。 But once the connection is established the structure of the packages won't change, so maybe parts of the parsing could be skipped. 但是一旦建立连接,包的结构就不会改变,因此可能会跳过部分解析。

If parsing speed is a key factor for you, consider using cElementTree or lxml . 如果解析速度是您的关键因素,请考虑使用cElementTreelxml

There are definitely more options out there, see these threads: 肯定有更多的选择,请看这些主题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM