jkl-parsexmlで配列になっている属性値にアクセスする方法

jkl-parsexml.js:属性値のアクセス方法」というエントリーを2年ぐらい前に書いたんだけれども、今回こういうXMLをパースする時に<comment>○○○</comment>のなかのテキストをとる方法が分からなくてハマったのでメモ。

<rsp stat="ok">
<comments photo_id="2328202849">
    <comment authorname="micstolz" datecreate="1205375350">
 Great red and gray!</comment>
</comments>
<comments photo_id="2328202849">
    <comment authorname="javababy" datecreate="1205375351">
 beautifui</comment>
</comments>
</rsp>

こうやるだけ。

data["rsp"]["comments"]["comment"][i]["#text"];

かなり悩んだけどfirebug使ったら簡単だった。これ便利だね。

This entry was posted in Javascript. Bookmark the permalink.

コメントをどうぞ

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>