需要xpath查询的帮助

时间:2016-03-25 14:17:00

标签: xml facebook xpath element treenode

有人可以帮我制定一个xpath查询吗?我有这个xml文件,其中包含从facebook下载的帖子的信息

 ...
<Post>
    <CreationDate>Sun Mar 20 08:20:00 CET 2016</CreationDate>
    <Id>179618821150_10154060429226151</Id>
    <Newspaper>Repubblica</Newspaper>
    <Snippet>Da Roma alle Marche. Il cammino sacro apre ai ciclisti</Snippet>
    <Text>Il ciclo-pellegrinaggio arriva anche in Italia</Text>
    <Hashtags/>
    <Likes>25</Likes>
    <Shares>167</Shares>
    <URL>http://larep.it/1Rtgs36</URL>
    <Picture/>
    <Sentiment>0</Sentiment>
    <IsIndexed>True</IsIndexed>
    <IsTokenized>False</IsTokenized>
</Post>
<Post>
    <CreationDate>Wed Mar 16 18:10:00 CET 2016</CreationDate>
    <Id>179618821150_10154051153841151</Id>
    <Newspaper>Repubblica</Newspaper>
    <Snippet>Il Dalai Lama scrive a Pannella: "Prego per te e la tua       famiglia"</Snippet>
    <Text>La commovente lettera: "Come sai, ti considero un amico personale e un inamovibile amico del popolo tibetano di lunga data. Prego per te"</Text>
    <Hashtags/>
    <Likes>25</Likes>
    <Shares>5</Shares>
    <URL>http://larep.it/1nOztp9</URL>
    <Picture/>
    <Sentiment>0</Sentiment>
    <IsIndexed>True</IsIndexed>
    <IsTokenized>False</IsTokenized>
</Post>
...

我需要获得所有名为&#34; Post&#34;包含元素&#34; CreationDate&#34;从一些文字X开始。我怎么能这样做呢? 我目前正在使用此查询,但它只选择CreationDate元素...

 /Posts/Post/CreationDate[starts-with(.,'" + someText + "')]

感谢!!! :)

2 个答案:

答案 0 :(得分:2)

您的XPath几乎是正确的,除了它返回CreationDate而不是Post。试试这个:

/Posts/Post[starts-with(CreationDate,'" + someText + "')]

答案 1 :(得分:0)

尝试:

/Posts/Post[CreationDate[starts-with(.,'" + someText + "')]]