プロが教えるわが家の防犯対策術!

こんにちは。
はじめに、FlashやXMLに関しての知識はあまり無い為、分かりづらい点があるかもしれませんが、その点は出来る限り補足します。

自分のブログのタイトルとリンクを取り出し、ホームページ上に表示させる1行ティッカーを作りたいと思っています。
ブログとホームページは違うドメインなので、PHPでRSSを呼び出し、PHPをflashに読み込む事に成功しました。(traceで確認しました)

(このような感じになります)
RSS>>>[PHP>>>SWF]←ホームページのサーバー

そして、読み込んだRSSの中にある「タイトル、記事URL」の部分をそれぞれ変数に代入して表示させたいのですが、RSS(XML)の中から、あるタグの内容だけを取り出し、変数にする事は可能でしょうか?

回答、アドバイスよろしくお願いします。
(XMLを誤解している、こうした方が早い、というような回答も待っています。)

A 回答 (1件)

package Q4322233A


{

import flash.display.Sprite;
import flash.text.TextField;

public class Main extends Sprite
{
public function Main():void
{

//実験環境:Flex 3 SDK + FlashDevelop 3.0.0 Beta 9 + Windows XP SP3
//FlashDevelopのインストールやフォントその他の設定は済ませておくこと。

//なぜかFlashDevelopではtrace関数を実行してもoutputに出力がなされず
//その後いくつかのサイトを回って方法を試すもうまくいかなかったので,
//flash.display.SpriteにTextFieldを追加して,そこに出力している。

var textfield:TextField = new TextField();
textfield.multiline = true;
textfield.width = 2000;

addChild(textfield);


//http://www.23ch.info/test/read.cgi/swf/1194838207/

//91:
//ActionScript3で二点ほど質問をさせてください。
//2) XMLクラスに対してString形式のXPathでアクセスするにはどうしたらいいでしょうか?

//94:
//2)E4Xが標準だからそっち覚える。どうしてもxpathじゃなきゃまずいなら3.0使わずに2.0のmx.xpath.XPathAPIでどうぞ。

//himajin100000:このE4Xのリテラル,気持ち悪くて嫌いだ。
//使っているFlashDevelop 3.0.0 Beta 9だと,リテラルとコメントの開始が区別できてなくて色分けがおかしい

//思想的に好きなのはRSS 1.0なのでサンプルとして取り上げる。
//RSS 0.9x,RSS 2.0,Atomは取り上げない。

//教えてgooはダブルクオートの前後にZERO WIDTH SPACEを埋め込むため,(俺の方で回避不能)
//この回答のコードを直接貼り付けても動作しない。該当する文字を置換で置き換えてから使うなり,自分で手打ちするなりしてくれ。


var doc:XML =
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://purl.org/rss/1.0/">

<channel rdf:about="http://www.xml.com/xml/news.rss">
<title>XML.com</title>
<link>http://xml.com/pub</link>
<description>
XML.com features a rich mix of information and services
for the XML community.
</description>
<image rdf:resource="http://xml.com/universal/images/xml_tiny.gif" />

<items>
<rdf:Seq>
<rdf:li rdf:resource="http://xml.com/pub/2000/08/09/xslt/xslt.html" />
<rdf:li rdf:resource="http://xml.com/pub/2000/08/09/rdfdb/index.html" />
</rdf:Seq>
</items>
<textinput rdf:resource="http://search.xml.com" />
</channel>

<image rdf:about="http://xml.com/universal/images/xml_tiny.gif">
<title>XML.com</title>
<link>http://www.xml.com</link>
<url>http://xml.com/universal/images/xml_tiny.gif</url>
</image>

<item rdf:about="http://xml.com/pub/2000/08/09/xslt/xslt.html">
<title>Processing Inclusions with XSLT</title>
<link>http://xml.com/pub/2000/08/09/xslt/xslt.html</li …
<description>
Processing document inclusions with general XML tools can be
problematic. This article proposes a way of preserving inclusion
information through SAX-based processing.
</description>
</item>

<item rdf:about="http://xml.com/pub/2000/08/09/rdfdb/index.html">
<title>Putting RDF to Work</title>
<link>http://xml.com/pub/2000/08/09/rdfdb/index.html</ …
<description>
Tool and API support for the Resource Description Framework
is slowly coming of age. Edd Dumbill takes a look at RDFDB,
one of the most exciting new RDF toolkits.
</description>
</item>

<textinput rdf:about="http://search.xml.com">
<title>Search XML.com</title>
<description>Search XML.com's XML collection</description>
<name>s</name>
<link>http://search.xml.com</link>
</textinput>
</rdf:RDF>

//最後にセミコロンは要らない。

var rdf:Namespace = new Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#");
var rss:Namespace = new Namespace("http://purl.org/rss/1.0/");

//XMLを理解してないと,(どの要素がどの名前空間に属するかとか)右辺がかけないような気がする。
//これは,まぁE4Xじゃなくても同じだけど
//その説明は一切しないので勉強して欲しい。
var itemList:XMLList = doc.rss::item;

//表示内容
//Processing Inclusions with XSLT:http://xml.com/pub/2000/08/09/xslt/xslt.html
//Putting RDF to Work:http://xml.com/pub/2000/08/09/rdfdb/index.html

for each(var item:XML in itemList) {
textfield.appendText(item.rss::title + ":" + item.rss::link + "\n");
}

//後は出力内容に応じてどうぞ。
}
}
}

この回答への補足

すみません!
私の環境は、WindowsXP、Flash8、FlashPlayer9.0で、ActionScript2.0を使用しています。

補足日時:2008/09/12 08:58
    • good
    • 0
この回答へのお礼

回答ありがとうございます。

おかげさまで、変数にXML全体を読み込むことは出来ました。
せっかく回答して頂いたのに、説明不足で申し訳ありませんでした。

お礼日時:2008/09/12 08:58

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!