0

我有一个示例 xml 文件,如下所示。我可以有 100 个条目标签,其中包含有关每个条目的信息。我所追求的是最终和之前关闭 xml 结构。

<feed xml:base="http://odata.me.com/v1/Catalog/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">Videos</title>
<id>http://odata.me.com/v1/Catalog/Videos</id>  
 <link rel="self" title="Videos" href="Videos" />

 <entry>
    <id>http://odata.me.com/v1/Catalog/Videos('AEAB20400094')</id>
    <title type="text"></title>
    <updated>2012-05-08T19:20:08Z</updated>
    <author>
      <name />
    </author>
    <link rel="edit" title="VideoEf" href="Videos('AEAB20400094')" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentProviderEntity" type="application/atom+xml;type=entry" title="ContentProviderEntity" href="Videos('AEAB20400094')/ContentProviderEntity" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/VideoVersionsCollection" type="application/atom+xml;type=feed" title="VideoVersionsCollection" href="Videos('AEAB20400094')/VideoVersionsCollection" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/VideoBuyLinksCollection" type="application/atom+xml;type=feed" title="VideoBuyLinksCollection" href="Videos('AEAB20400094')/VideoBuyLinksCollection" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/VideoMetadatasCollection" type="application/atom+xml;type=feed" title="VideoMetadatasCollection" href="Videos('AEAB20400094')/VideoMetadatasCollection" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/VideoPoliciesCollection" type="application/atom+xml;type=feed" title="VideoPoliciesCollection" href="Videos('AEAB20400094')/VideoPoliciesCollection" />
    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/GenresCollection" type="application/atom+xml;type=feed" title="GenresCollection" href="Videos('AEAB20400094')/GenresCollection" />
    <category term="Me.Data.EF.Entities.VideoEf" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
    <content type="application/xml">
      <m:properties>
        <d:Isrc>AEAB20400094</d:Isrc>
        <d:Title>Akhasmak Ah</d:Title>
        <d:ThumbnailFilename>03FE946D8DC4D4E82A1EA56DD9EB89DA.jpg</d:ThumbnailFilename>
        <d:ContentProviderID m:type="Edm.Int32">11</d:ContentProviderID>
        <d:DurationInSeconds m:type="Edm.Int32">17</d:DurationInSeconds>
        <d:CreationDate m:type="Edm.DateTime">2010-10-26T21:57:30.363</d:CreationDate>
        <d:ModifiedDate m:type="Edm.DateTime">2012-05-03T20:56:42.383</d:ModifiedDate>
        <d:StartDate m:type="Edm.DateTime">2009-07-13T00:00:00</d:StartDate>
        <d:EndDate m:type="Edm.DateTime" m:null="true" />
        <d:CopyrightLine>(P) 2002 The copyright in this audiovisual recording is owned by Relax-In/Megastar under exclusive license to EMI Music Arabia</d:CopyrightLine>
        <d:FilteredTitle>Akhasmak Ah</d:FilteredTitle>
        <d:ThumbnailUrl>http://cache.me.com/Content/MeImages/video/03FE946D8DC4D4E82A1EA56DD9EB89DA.jpg</d:ThumbnailUrl>
      </m:properties>
    </content>
</entry>
 <link rel="next" href="http://odata.me.com/v1/Catalog/Videos?$skiptoken='AUBM80800189'" />  
</feed>

有谁知道我怎样才能抓住最后一个元素..我正在寻找href中的值。

哦,我在 PHP5 中这样做

谢谢

4

2 回答 2

2

Xpath 是你的朋友 :) 类似:

//link[@rel='next']/@href

我不确定上面的 xpath 是否完全正确(没有尝试过),但它是这样的。它还基于这样的假设,即您所追求的最后一个链接元素始终具有 rel 属性的值为“下一个”

您需要使用一些 php xpath 库来使用它。一些 PHP 示例代码:

$doc = new DOMDocument();
$doc->loadXML($data);
$xp = new DOMXPath($doc);
$xp->registerNamespace('atom', 'http://www.w3.org/2005/Atom');
var_dump($xp->evaluate('string(//atom:link[@rel="next"]/@href)')) ;
于 2012-05-08T20:31:03.703 回答
1

在这些相同的示例中,标题可以通过

$title=$xp->evaluate('string(//atom:content/m:properties/d:Title)');
于 2012-11-14T09:37:24.083 回答