解析XML,日期格式(PT0H0M0S,PT2920H0M0S)

4

我正在尝试使用Python解析从MS Project 2013导出的XML文件,并且它包含以下数据:

<TimephasedData>
    <Type>1</Type>
    <UID>4628</UID>
    <Start>2014-09-22T08:00:00</Start>
    <Finish>2015-09-22T08:00:00</Finish>
    <Unit>8</Unit>
    <Value>PT2920H0M0S</Value>
</TimephasedData>
<TimephasedData>
    <Type>1</Type>
    <UID>4628</UID>
    <Start>2015-09-22T08:00:00</Start>
    <Finish>2015-09-23T08:00:00</Finish>
    <Unit>2</Unit>
    <Value>PT8H0M0S</Value>
</TimephasedData>

我不理解PT8H0M0S和PT2920H0M0S代表什么意思(TimephasedData)。目前,我通过替换字符“T”来解析日期,然后使用strptime

1个回答

5
这是一个ISO 8601时间持续值。与iCal duration data type规范相比,它使用了这种符号表示:

Formal Definition

The value type is defined by the following notation:

dur-value  = (["+"] / "-") "P" (dur-date / dur-time / dur-week)
dur-date   = dur-day [dur-time]   
dur-time   = "T" (dur-hour / dur-minute / dur-second)
dur-week   = 1*DIGIT "W"
dur-hour   = 1*DIGIT "H" [dur-minute]
dur-minute = 1*DIGIT "M" [dur-second]  
dur-second = 1*DIGIT "S"
dur-day    = 1*DIGIT "D"
所以,PT8H0M0S代表时间段(T),8小时(8H),0分钟(0M),0秒钟(0S)。 (当然,P代表“周期”)。
至少有一个Python包可以处理这些类型的值,例如https://pypi.python.org/pypi/isodate

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接