0

この XML スタイル ファイルからデータを取得しようとしています:

<Product_Group>
  <Product_Group_ID>131</Product_Group_ID>
  <Product_Group_Title>Thanks for the Memories</Product_Group_Title>
  <Products>
    <On_Sale_Date>03/01/12 00:00:00.000</On_Sale_Date>
    <ISBN>9780007233694</ISBN>
    <Title>Thanks for the Memories</Title>
    <Format>Paperback</Format>
    <Sub_Format/>
    <CoverImageURL_Small>http://www.harpercollins.com/harperimages/isbn/small/4/9780007233694.jpg</CoverImageURL_Small>
  </Products>
</Product_Group>

次のコードを使用していますが、これは何も取得していないようです。この問題を解決するための助けをいただければ幸いです

$xml = simplexml_load_string($response);
//$xml= $response;
$updates = array();
//loop through all the entry(s) in the feed
for ($i=0; $i<count($xml->Product_Group); $i++)
{
    //get the id from entry
    $ISBN = $xml->entry[$i]->ISBN;

    //get the account link
    $Title = $xml->entry[$i]->Title;

    //get the tweet
    $Product_Group_SEO_Copy = $xml->entry[$i]->Product_Group_SEO_Copy;  
}
4

1 に答える 1

0

1) 有効な XML ではありません。どのような警告が表示されますか? simplexml_load_string正しく動作させるには、それらを修正する必要があります。

たとえば</CoverImageURL_Small><CoverImageURL_Small/>

Product_Group2)それが実際のドキュメントルートではないと仮定すると(それが$xmlすでにそれを指していて$xml->Product_Group機能しない場合)、次のような各要素にアクセスできます

$xml->Product_Group->Products[$i]->ISBN;

3) simplexml を扱うときは通常、foreachループよりもループを使用する方が簡単です。for

foreach($xml->Product_Group->Products as $p)
{
    $ISBN = $p->ISBN;
    //var_dump($ISBN);
}
于 2012-04-28T08:32:26.683 に答える