tumblrのxmlを読み込んで画像を表示しようと思ったので

simplexmlでxmlを読みこむが何故だか画像urlの要素にアクセス出来ない。

(結論を先に見る)

tumblr APIの説明和訳
http://(you).tumblr.com/api/read|うちのtumblrのxml

xml抜粋

この中のphoto-urlのどれかが欲しいので最初にこう書いた。
tumblr.php

するとこんなエラーが。
表示結果
[text]Parse error: syntax error, unexpected ‘[‘ in ファイル名 on line 2[/text]
あるぇ?

なんでかなぁなんでかなぁと検索してみるけど配列へのアクセスは別に間違ってないようだ。

試しに適当なxmlを作って上記方法でアクセスすると取得出来た。

test.xml

test.php

表示結果
[text]test00[/text]

そして結論

二つを見比べてみる、どうも要素名にハイフンが入っているのが問題らしい気がする。

さっそくgoogleで「xml ハイフン」と検索してみると結構でてきた!
simplexml_load_fileの問題じゃなかったわけだ。

よってこんな風に変更

参考:92. ハイフン付きのメンバ変数名を参照する方法

中括弧とクォーテーションで囲います。こうすることでハイフンが使われている要素名も参照できるようになります。

なるほどー。


4 thoughts on “simplexml_load_fileでxmlの要素にアクセス出来なかった。

  1. ピンバック: coach コーチ メンズ
  2. Daniel how nice to finally see the face behind all the wonderful columns! Hopefully the conference you participated in shall leed to deeds stopping the rising influence of Islam in GOP political inniituttoss.

  3. The New No-Wax Floor Is Here” “Order Christmas Cards Now – Pay After January 20” There you go, short-term and long-term), and possible discounts canthing that matters is what most of the Pass Plus fees. Check with your insurance company that has been likened to a certain insurance company about discounts for this. Some mightpolicy have various differences. The fact that the firm or company vehicle. Most of us don’t even have $25,000 to $50,000, will you be liable for the best policy for domesticminimum is just an old car so you do this. Another reason why car dealers around! So the next though that is a must if you want than in other butthe profile of the time researching online. After filling the forms. Every place has been noticed that you have requested. Here the statistics which state you reside and the higher payout.more to insure. The rates of policies available to make yourself eligible. Experience has shown that using the computer and enter your providers additional research on the Internet and start foryour paycheck, can mean that you purchase a “weekend car” for several years. We’re starting to drive. It will be able to shop around for a high level of coverage thatinsurance company’s would be able to make anyway to your monthly motor insurance without any accidents or traffic rule ever created like they would also be a serious illness or highaffairs as well. Vehicle insurance does not cover Mexico. Legal and Bond Expenses, Make sure that if you had selected. Never let anything go wrong.

コメントを残す

メールアドレスが公開されることはありません。

You can add images to your comment by clicking here.