<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BPS株式会社 開発ブログ Beyond Perspective Solutions LTD. &#187; XML</title>
	<atom:link href="http://www.bpsinc.jp/blog/archives/tag/xml/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bpsinc.jp/blog</link>
	<description>BPS株式会社（Beyond Perspective Solutions）のプログラマによる技術・開発などに関してのブログです</description>
	<lastBuildDate>Wed, 20 Jul 2011 08:14:42 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Android 1.5でTabHostを使った場合、StackOverflowErrorが発生する</title>
		<link>http://www.bpsinc.jp/blog/archives/2224</link>
		<comments>http://www.bpsinc.jp/blog/archives/2224#comments</comments>
		<pubDate>Fri, 30 Jul 2010 09:10:17 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[エラー]]></category>
		<category><![CDATA[タブ]]></category>
		<category><![CDATA[バグ]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=2224</guid>
		<description><![CDATA[Androidで便利な、タブ表示。
これは、TabActivity, TabHost, TabSpecを使って簡単に実現できます。
src/MainActivity.java
package jp.bpsinc.andr [...]]]></description>
			<content:encoded><![CDATA[<p>Androidで便利な、タブ表示。</p>
<div id="attachment_2225" class="wp-caption aligncenter" style="width: 207px"><a href="http://www.bpsinc.jp/blog/wp-content/uploads/2010/07/tab.png"><img class="size-medium wp-image-2225" title="tab" src="http://www.bpsinc.jp/blog/wp-content/uploads/2010/07/tab-197x300.png" alt="タブ表示" width="197" height="300" /></a><p class="wp-caption-text">タブ表示</p></div>
<p>これは、TabActivity, TabHost, TabSpecを使って簡単に実現できます。</p>
<p>src/MainActivity.java</p>
<pre class="brush:java">package jp.bpsinc.android.tabtest;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

public class MainActivity extends TabActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TabHost tabHost = getTabHost();
    LayoutInflater.from(this).inflate(R.layout.main, tabHost.getTabContentView(), true);

    //タブを作る
    TabSpec tab1 = tabHost.newTabSpec("tab1");
    tab1.setIndicator("tab1");
    tab1.setContent(R.id.tab1);

    TabSpec tab2 = tabHost.newTabSpec("tab2");
    tab2.setIndicator("tab2");
    tab2.setContent(R.id.tab2);

    tabHost.addTab(tab1);
    tabHost.addTab(tab2);
  }
}</pre>
<p>res/layout/main.xml</p>
<pre class="brush:xml">&#60;?xml version="1.0" encoding="utf-8"?&#62;
&#60;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;

  &#60;TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="TAB1" android:id="@+id/tab1" /&#62;
  &#60;TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="TAB2" android:id="@+id/tab2" /&#62;
&#60;/FrameLayout&#62;</pre>
<p>しかし、サンプルでなく複雑なアプリを作ると、<strong>Android 1.5 (SDK Version 3) の時だけ、StackOverflowErrorが発生する</strong>という現象に見舞われることがあります。</p>
<blockquote><p>body : java.lang.StackOverflowError<br />
at android.text.TextUtils#getChars:69<br />
at android.graphics.Canvas#drawText:1278<br />
at android.text.Layout#draw:337<br />
at android.widget.TextView#onDraw:3921<br />
at android.view.View#draw:5838<br />
at android.view.ViewGroup#drawChild:1486<br />
at android.view.ViewGroup#dispatchDraw:1228<br />
at android.view.ViewGroup#drawChild:1484<br />
at android.view.ViewGroup#dispatchDraw:1228<br />
at android.view.ViewGroup#drawChild:1484<br />
at android.view.ViewGroup#dispatchDraw:1228<br />
at android.view.ViewGroup#drawChild:1484<br />
at android.view.ViewGroup#dispatchDraw:1228<br />
at android.widget.AbsListView#dispatchDraw:1319<br />
at android.widget.ListView#dispatchDraw:2820<br />
at android.view.View#draw:5944<br />
&#8230;.</p></blockquote>
<p><a href="http://groups.google.co.jp/group/android-developers/msg/c7472f71aa9e41c5">こちらのGoogleGroupディスカッション</a>でも触れられているようですが、Android 1.5では、タブの中に多重にネストしたコンテンツがあると、StackOverflowErrorが発生します。</p>
<p>手元のエミュレータで試したところ、12回ネストしたところで、エラーになりました。</p>
<pre class="brush:xml">&#60;?xml version="1.0" encoding="utf-8"?&#62;
&#60;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;

  &#60;TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="TAB1" android:id="@+id/tab1" /&#62;

  &#60;FrameLayout android:id="@+id/tab2" android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
    &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
      &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
        &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
          &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
            &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
              &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
                &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
                  &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
                    &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
                      &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
                        &#60;LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent"&#62;
                          &#60;TextView android:text="TAB2" android:layout_width="wrap_content" android:layout_height="wrap_content" /&#62;
                        &#60;/LinearLayout&#62;
                      &#60;/LinearLayout&#62;
                    &#60;/LinearLayout&#62;
                  &#60;/LinearLayout&#62;
                &#60;/LinearLayout&#62;
              &#60;/LinearLayout&#62;
            &#60;/LinearLayout&#62;
          &#60;/LinearLayout&#62;
        &#60;/LinearLayout&#62;
      &#60;/LinearLayout&#62;
    &#60;/LinearLayout&#62;
  &#60;/FrameLayout&#62;
&#60;/FrameLayout&#62;</pre>
<p>XMLをパーツに分けて書いていると、うっかり12回を超えてしまうことがあるので、注意が必要です。<br />
解決策としては、ネスト回数を減らすか、Android 1.5を対象から外すという後ろ向きなものが最適ですね。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/2224/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AndroidにAdMob広告を配置する入門</title>
		<link>http://www.bpsinc.jp/blog/archives/2111</link>
		<comments>http://www.bpsinc.jp/blog/archives/2111#comments</comments>
		<pubDate>Wed, 14 Jul 2010 03:34:41 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[Ad]]></category>
		<category><![CDATA[AdMob]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[広告]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=2111</guid>
		<description><![CDATA[インプレッション表示の収入がないとか、クリック単価が低いとか、なかなか広告が出ないとか、アプリ・Web開発者側からするとお金にしづらいAdMobではありますが、すごく使いやすいので、使っている方も多いと思います。
And [...]]]></description>
			<content:encoded><![CDATA[<p>インプレッション表示の収入がないとか、クリック単価が低いとか、なかなか広告が出ないとか、アプリ・Web開発者側からするとお金にしづらいAdMobではありますが、すごく使いやすいので、使っている方も多いと思います。</p>
<p>Androidに完全対応した（少ない手間で組み込める）数少ない広告システムということもあり、色々お世話になります。</p>
<p>今回は、AdMobの登録～Androidで広告を表示してみるまでの簡単な手順と、注意点です。</p>
<h4>登録</h4>
<p><a href="http://jp.admob.com/">http://jp.admob.com/</a>から登録します。</p>
<h4>アプリケーションを追加</h4>
<p>ログインしたら上部タブから「マーケットプレイス」を選択します。<br />
「キャンペーン」は広告主用のものなので、開発者は「サイト及びアプリケーション」を開きます。</p>
<p>「サイト・アプリケーションを追加」ボタンをクリックし、「Android」ボタンをクリックすると、アプリ情報入力画面になります。<br />
ここに入力した内容に間違いがあっても、広告が表示されない、ということはありませんが、なるべく正直に入力しましょう。</p>
<h4>SDKのダウンロード</h4>
<p>アプリの登録を完了すると、SDKとマニュアルPDFがダウンロードできるようになります。<br />
SDKはダウンロード・解凍して、適当な場所に置いておきます。同フォルダにAdMobSDKのリファレンス（JavaDoc）もあるので、是非参考にしてください。</p>
<p>これ以降の手順は、PDFに従うのが一番です！！</p>
<h4>広告が表示されないとき</h4>
<p>ということで、解説を途中で放棄して、「PDF通りにやったのに広告が表示されない」という場合のチェックポイントです。<br />
基本的に、ManifestにパブリッシャーIDを入れて、attrs.xml、表示したいViewのXMLを書けばOKなのですが、以下の場合、広告が表示されません。</p>
<p>・ネットワーク接続できない<br />
この場合、広告は取得できず、何も表示されません。</p>
<p>・表示領域が狭い<br />
AdViewのサイズは、横幅320px以上である必要があります。それより小さいと、何も出てきません。</p>
<p>・ログに「no ads are available」と出る場合<br />
広告がありません。AdMobは広告主に比べて開発者が多いのか、広告が見つからないことが良くあります。<br />
この場合、Webの管理画面から「自社広告」を入れておけば、何も見つからないときに自社広告を表示することができます。</p>
<p>・単に遅い<br />
Viewが表示されてから広告が表示されるまで、数秒かかるのが普通です。<br />
上部に入れる場合は、48pxくらいの高さを確保しておいた方が、レイアウトが変わらなくて良いかもしれません。</p>
<h4>動的にキーワードフィルタする</h4>
<p>Web管理画面から、表示する広告のジャンル、キーワードフィルタ等を設定することができます。<br />
しかし、アプリのコードから指定すれば、現在表示しているコンテンツにマッチした広告を表示することも可能です。</p>
<p>以下のようなコードで可能です。</p>
<pre class="brush:java">
AdView ad = (AdView)findViewById(R.id.ad);
ad.setKeywords("music");
</pre>
<p>とても多機能なAdMob、うまく使いこなしたいですね。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/2111/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Androidの多言語対応strings.xmlを効率的に管理する</title>
		<link>http://www.bpsinc.jp/blog/archives/2094</link>
		<comments>http://www.bpsinc.jp/blog/archives/2094#comments</comments>
		<pubDate>Mon, 12 Jul 2010 05:52:44 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[マクロ]]></category>
		<category><![CDATA[ロケール]]></category>
		<category><![CDATA[国際化]]></category>
		<category><![CDATA[多言語]]></category>
		<category><![CDATA[翻訳]]></category>
		<category><![CDATA[言語]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=2094</guid>
		<description><![CDATA[Androidは多言語対応が簡単で、
values/strings.xml
values-ja/string.xml
などの言語ファイルを作るだけで、システムロケールにあわせて自動的に多言語対応されます。
しかし、開発し [...]]]></description>
			<content:encoded><![CDATA[<p>Androidは多言語対応が簡単で、</p>
<p>values/strings.xml<br />
values-ja/string.xml</p>
<p>などの言語ファイルを作るだけで、システムロケールにあわせて自動的に多言語対応されます。</p>
<p>しかし、開発しながらstrings.xmlを書いていくと、複数言語を管理するのはかなり大変。<br />
また、開発者以外の翻訳者にXMLを書かせるのも酷な話です。</p>
<p>ということで、万能ツールExcel君の出番です。</p>
<p>簡単なVBAスクリプトで、Excel管理している言語ファイルから、strings.xmlを出力する機能を作りました。<br />
（たぶん似たようなことをやっている方は多いですよね・・・）</p>
<div id="attachment_2095" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.bpsinc.jp/blog/wp-content/uploads/2010/07/ex2.png"><img src="http://www.bpsinc.jp/blog/wp-content/uploads/2010/07/ex2-300x88.png" alt="言語ファイル" title="ex2" width="300" height="88" class="size-medium wp-image-2095" /></a><p class="wp-caption-text">言語ファイル</p></div>
<p>これを使えば、</p>
<p>・日本語にはあるのに英語には無い！などの、strings.xmlの記述ミスが無くなります<br />
・Excelなので、XMLを分からない人にも翻訳をお願いできます<br />
・一括生成で、スピーディーに言語のアップデートができます</p>
<p>作ってみたばかりで、不具合等あるかもしれませんが、是非お試し下さい。<br />
フィードバック頂ければ幸いです。</p>
<p><a href='http://www.bpsinc.jp/blog/wp-content/uploads/2010/07/languages.zip'>ダウンロード</a></p>
<p>※VBAマクロなので、Excel設定でマクロを許可して下さい<br />
※Excel 2007で作成しています<br />
※UTF-8対応のため、<a href="http://www.vector.co.jp/soft/dl/winnt/prog/se320375.html">UTF-8ファイル作成 for VBA</a>のライブラリを使わせて頂きました。作者様に感謝致します。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/2094/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RailsのHash.from_xmlに注意</title>
		<link>http://www.bpsinc.jp/blog/archives/1597</link>
		<comments>http://www.bpsinc.jp/blog/archives/1597#comments</comments>
		<pubDate>Tue, 25 May 2010 01:34:14 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=1597</guid>
		<description><![CDATA[RailsのActiveSupportは大変便利で、生Ruby使うときも

irb -r rubygems -r active_support

をデフォルトにしたくなります。
# 個人的には .blank? が一番便利 [...]]]></description>
			<content:encoded><![CDATA[<p>RailsのActiveSupportは大変便利で、生Ruby使うときも</p>
<pre class="brush:bash">
irb -r rubygems -r active_support
</pre>
<p>をデフォルトにしたくなります。</p>
<p># 個人的には .blank? が一番便利だと思います。</p>
<p>ところで、Hash.from_xmlを使うとお手軽にXMLをパースできますが、若干癖があるので注意が必要です。<br />
・子要素も属性も同じように扱われる<br />
・同じ名前の要素が複数あると自動で配列になる<br />
・typeという名前の属性は、無視されることがある<br />
・ハイフンはアンダースコアに置換される</p>
<p>たとえば、user-listの中にuserが複数ある場合、</p>
<pre class="brush:ruby">
{"user_list" =&#62; {"user" =&#62; &#91;"yamada", "tanaka"&#93;}}
</pre>
<p>のように変換されるため、扱いやすいのですが、userがたまたま1件だと、</p>
<pre class="brush:ruby">
{"user_list" =&#62; {"user" =&#62; "yamada"}}
</pre>
<p>のようになり、userが配列と期待しているプログラムは動かなくなります。<br />
特に、検索系のXMLを使う際は注意が必要です。</p>
<p>また、属性は子要素のように使えますが、属性が1つだけだったり、子要素が文字列の場合、扱いが変わったり消えてしまうことがあるので、注意しましょう。</p>
<p>以下に例を挙げます。</p>
<pre class="brush:ruby">
&#60;a&#62;&#60;b size="123"&#62;456&#60;/b&#62;&#60;/a&#62;
=&#62; {"a" =&#62; {"b" =&#62; "456"}}

&#60;a&#62;&#60;b size="123" /&#62;&#60;/a&#62;
=&#62; {"a" =&#62; {"b" =&#62; "123"}}

&#60;a&#62;&#60;b type="123" /&#62;&#60;/a&#62;
=&#62; {"a" =&#62; {"b" =&#62; nil}}

&#60;a&#62;&#60;b size="123"&#62;&#60;c&#62;456&#60;/c&#62;&#60;/b&#62;&#60;/a&#62;
=&#62; {"a" =&#62; {"b" =&#62; {"size" =&#62; "123", "c" =&#62; "456"}}}

&#60;a&#62;&#60;b type="123"&#62;&#60;c&#62;456&#60;/c&#62;&#60;/b&#62;&#60;/a&#62;
=&#62; {"a" =&#62; {"b" =&#62; {"c" =&#62; "456", "type" =&#62; "123"}}}
</pre>
<p>複雑なXMLをパースする際は、ちゃんとnokogiriなどのライブラリを使うと良さそうですね。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/1597/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EthnaでXML-RPCの引数を連想配列にする</title>
		<link>http://www.bpsinc.jp/blog/archives/190</link>
		<comments>http://www.bpsinc.jp/blog/archives/190#comments</comments>
		<pubDate>Wed, 04 Mar 2009 13:40:22 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ネットワーク]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML-RPC]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=190</guid>
		<description><![CDATA[Ethnaは標準でXML-RPCに対応しているので、
# ethna add-action-xmlrpc hoge
とやるだけで app/action-xmlrpc にActionのテンプレートが作れますし、クライアント [...]]]></description>
			<content:encoded><![CDATA[<p>Ethnaは標準でXML-RPCに対応しているので、<br />
# ethna add-action-xmlrpc hoge<br />
とやるだけで app/action-xmlrpc にActionのテンプレートが作れますし、クライアントからHogeメソッドをコールすると、自動的にHogeアクションが実行されます。<br />
(エントリポイントはindex.phpではなくxmlrpc.phpになります)</p>
<p>しかし、デフォルトでは引数がActionFormのform定義と順番に1対1で対応するため、引数が多くなると使いづらくなります。</p>
<p>ここは、PHPらしく引数名をキーにした連想配列にしたいところ。<br />
(プロジェクト名)_Controller に以下のメソッドを定義(オーバーライド)することで、XMLRPCの第一引数を連想配列として扱い、対応する名前のformに値がセットされるようになります。</p>
<p><code>function trigger_XMLRPC($method, $param)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;// アクション定義の取得<br />
&nbsp;&nbsp;&nbsp;&nbsp;$action_obj =&#038; $this->_getAction($method);<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (is_null($action_obj)) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return Ethna::raiseError("undefined xmlrpc method [%s]", E_APP_UNDEFINED_ACTION, $method);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;// オブジェクト生成<br />
&nbsp;&nbsp;&nbsp;&nbsp;$backend =&#038; $this->getBackend();</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;$form_name = $this->getActionFormName($method);<br />
&nbsp;&nbsp;&nbsp;&nbsp;$this->action_form =&#038; new $form_name($this);<br />
&nbsp;&nbsp;&nbsp;&nbsp;$def = $this->action_form->getDef();<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;/***** ここから変更 *****/<br />
&nbsp;&nbsp;&nbsp;&nbsp;if (isset($param[0]) &#038;&#038; is_array($param[0]))<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;foreach ($param[0] as $key => $value)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (isset($def[$key]))<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this->action_form->set($key, $value);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;/***** ここまで変更 *****/</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;// バックエンド処理実行<br />
&nbsp;&nbsp;&nbsp;&nbsp;$backend->setActionForm($this->action_form);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;$session =&#038; $this->getSession();<br />
&nbsp;&nbsp;&nbsp;&nbsp;$session->restore();<br />
&nbsp;&nbsp;&nbsp;&nbsp;$r = $backend->perform($method);</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;return $r;<br />
}<br />
</code></p>
<p>これで、クライアント側では引数の順番を気にせずに済みます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/190/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML-RPC</title>
		<link>http://www.bpsinc.jp/blog/archives/175</link>
		<comments>http://www.bpsinc.jp/blog/archives/175#comments</comments>
		<pubDate>Fri, 27 Feb 2009 00:03:05 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XML-RPC]]></category>
		<category><![CDATA[バグ]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=175</guid>
		<description><![CDATA[PHPでXML-RPCを使った記録です。
PEAR::XML_RPC2を使うことにしました。PHP5専用で使いやすそうです。

PHP5以上
cURLのエクステンション

が必須です。
クライアント側では、

requi [...]]]></description>
			<content:encoded><![CDATA[<p>PHPでXML-RPCを使った記録です。<br />
PEAR::XML_RPC2を使うことにしました。PHP5専用で使いやすそうです。</p>
<ul>
<li>PHP5以上</li>
<li>cURLのエクステンション</li>
</ul>
<p>が必須です。</p>
<p>クライアント側では、<br />
<code><br />
require_once './XML/RPC2/Client.php';<br />
$options = array('debug' => true);<br />
$client = XML_RPC2_Client::create('http://www.bpsinc.jp/xmlrpc.php', $options); //URLはダミー<br />
try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;$result = $client->Version(); //関数名はサーバ側で定義したもの<br />
&nbsp;&nbsp;&nbsp;&nbsp;print_r($result);<br />
} catch (XML_RPC2_FaultException $e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;var_dump($e);<br />
} catch (Exception $e) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;var_dump($e);<br />
}<br />
</code></p>
<p>のように使えます。</p>
<p>しかし、これだとなぜか結果が全部NULLになることがあります。<br />
debugメッセージを見ると、Server Responseは正常なのに、Decoded ResultがNULLになっているように見えます。</p>
<p>この問題、Server側かHttpRequestの実装の問題だと思うのですが、Server ResponseのBodyの最初に改行が入っているのが原因でした。<br />
&quot;\n&lt;?xml version=&quot;1.0&quot;?&gt;&lt;methodResponse&gt; &#8230;&quot;</p>
<p>PEAR/XML/RPC2/Backend/Xmlrpcext/Client.php の112行目付近で、<br />
<code>$result = xmlrpc_decode($body, $this->encoding);</code><br />
となっているところを、<br />
<code>$result = xmlrpc_decode(trim($body), $this->encoding);</code><br />
とすれば直ります。(マルチバイト対応のtrimを書いた方が良いかもしれません)<br />
※XMLRPCEXT拡張モジュールが入っていない場合は、PEAR/XML/RPC2/Backend/PHP/Client.phpになります。</p>
<p>ライブラリを書き換えるのは強引ですが、xmlrpc_decode関数自体がEXPERIMENTALのままですし、あとはHttpRequestやサーバ側を変更しなければ行けないので、スマートな解決方法は思いつきません。<br />
とりあえずresultがnullになる問題は回避できました。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/175/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>オーバーライドでちょっとはまりました</title>
		<link>http://www.bpsinc.jp/blog/archives/148</link>
		<comments>http://www.bpsinc.jp/blog/archives/148#comments</comments>
		<pubDate>Thu, 22 Jan 2009 06:33:35 +0000</pubDate>
		<dc:creator>baba</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[馬場]]></category>
		<category><![CDATA[overload]]></category>
		<category><![CDATA[override]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[オーバーライド]]></category>
		<category><![CDATA[オーバーロード]]></category>
		<category><![CDATA[バグ]]></category>

		<guid isPermaLink="false">http://www.bpsinc.jp/blog/?p=148</guid>
		<description><![CDATA[C#で System.Xml.XmlDocument を使っています。
XmlDocument xmlDocument = new XmlDocument();
プレフィックス付きのノードを作るとき、たとえば

&#60; [...]]]></description>
			<content:encoded><![CDATA[<p>C#で System.Xml.XmlDocument を使っています。<br />
<code>XmlDocument xmlDocument = new XmlDocument();</code></p>
<p>プレフィックス付きのノードを作るとき、たとえば</p>
<pre><code>
&lt;s:root xmlns:s=&quot;urn:hogehoge-hoge&quot; &gt;
    &lt;s:child /&gt;
&lt;/s:root&gt;
</code></pre>
<p>というXMLを作りたいとして、<br />
<code><br />
XmlNode root = xmlDocument.CreateNode(XmlNodeType.Element, "s", "root", "hogehoge-hoge");<br />
XmlNode child = xmlDocument.CreateNode(XmlNodeType.Element, "s", "child", "hogehoge-hoge");<br />
root.AppendChild(child);<br />
</code><br />
とすると動きますが、毎回NamespaceURIを指定するのは変だと思います。<br />
しかし、最後の引数を指定しないと、prefixが出力されません。</p>
<p>また、<br />
<code>xmlDocument.Save("filename");</code><br />
でファイルに保存するのは1行ですが、string型で受け取ろうと思うと、<br />
<code><br />
StringWriter writer = new StringWriter();<br />
xmlDocument.Save(writer);<br />
string output = writer.ToString();<br />
</code><br />
としないといけません。</p>
<p>色々不便なので、XmlDocumentを継承したExtendedXmlDocumentを作りました。命名がSXGA並にださいですが。。<br />
このクラス内部では、prefixとnamespaceURIのHashtableを持っていて、一度指定すると以降はnamespaceURIを指定しなくても対応するものを用意してくれます。<br />
また、ToString() をオーバーライドしてあるので、1行で文字列を受け取れます。</p>
<p>・・・と、ここまでは良かったんですが（前置きが長い）、<br />
その後調子に乗ってCreateAttribute()をオーバーライドしたらはまりました。</p>
<p><code>public override XmlAttribute CreateAttribute(string prefix, string name, string value);</code><br />
を作って、内部で<br />
<code>base.CreateAttribute(name);</code><br />
を呼ぶと、StackOverflowExceptionが発生します。</p>
<p>どうやら、XmlDocument.CreateAttribute(string) 内部で CreateAttribute(string, string, string) を呼んでいたみたいです。<br />
C#のオーバーライドは動的にメソッドを呼んでくれるので、派生クラスのCreateAttribute(string, string, string) が呼ばれてしまって、その内部で CreateAttribute(string) を呼ぶと無限ループ、と。</p>
<p>.NET Frameworkの内部コードが見られれば一瞬で解決した問題なんですが。<br />
オーバーライドは慎重に使わないとバグの元ですね。オーバーロードと組み合わさるとたまに危険。気をつけます。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bpsinc.jp/blog/archives/148/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

