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 属性を持つ最後のリンク要素の値が「next」であるという前提にも基づいています。

これを使用するには、いくつかの 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 に答える