datetime.iso8601标记的XPath表达式

时间:2012-08-01 07:22:29

标签: xml qt xpath qml

我有这个示例XML-RPC响应:

<struct>
    <member><name>post_id</name><value><string>131</string></value></member>
    <member><name>post_title</name><value><string>Test with secret password</string></value></member>
    <member><name>post_date</name><value><dateTime.iso8601>20080404T09:38:05</dateTime.iso8601></value></member>
    <member><name>post_thumbnail</name><value><string>http://localhost/~herop-kde/wordpress/wp-content/themes/twentyeleven/images/thumbnails/119.jpg</string></value></member>
</struct>

我需要在QML中使用dateTime()函数(和其他相关函数的日期/时间)查询dateTime。使用此查询始终返回错误:

struct/member[name='post_date']/value/dateTime.iso8601/dateTime()

错误:

Error XPST0017 in [...] at line 2, column 96: fn:dateTime($arg1 as xs:date?, $arg2 as xs:time?) as xs:dateTime? requires at least 2 argument(s). 0 is therefore invalid.
[...]/Main.qml:37:13: QML XmlRole: invalid query: "struct/member[name='post_date']/value/dateTime.iso8601/dateTime()"

我仍然可以使用该格式成功查询其他字段。

1 个答案:

答案 0 :(得分:1)

如果xml包含格式正确的iso8601日期(2008-04-04T09:38:05),您可以使用xs:dateTime函数:

ListView {
    // ...
    model: XmlListModel {
        // ...
        query: "/struct/member"
        XmlRole {
            name: "dateTime"
            query: "xs:dateTime(value/dateTime.iso8601)"
        }
    }
    delegate: Text {
        text: model.dateTime
    }
}

否则你必须将它作为字符串并在你的javascript代码中进行转换/格式化。