<?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/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>MinorProbrem&#187; 上限</title>
	<atom:link href="http://hmlab.info/minor/tag/%e4%b8%8a%e9%99%90/feed/" rel="self" type="application/rss+xml" />
	<link>http://hmlab.info/minor</link>
	<description>グダグダ日記</description>
	<lastBuildDate>Wed, 27 Apr 2011 21:48:54 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://hmlab.info/minor/tag/%e4%b8%8a%e9%99%90/feed/" />
		<item>
		<title>Firefox限定問題、XMLHttpRequestでXMLとかKMLを読むときの4096byte制限について</title>
		<link>http://hmlab.info/minor/2008/12/20081222_1226593809/</link>
		<comments>http://hmlab.info/minor/2008/12/20081222_1226593809/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 15:00:54 +0000</pubDate>
		<dc:creator>Hex68</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[4096]]></category>
		<category><![CDATA[4096byte]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[kml]]></category>
		<category><![CDATA[normalize]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmlhttp]]></category>
		<category><![CDATA[上限]]></category>
		<category><![CDATA[読み込み]]></category>

		<guid isPermaLink="false">http://hmlab.info/minor/?p=3809</guid>
		<description><![CDATA[わけあって、KMLをJavascriptで読み込んだりしていた。 KMLとは、Googleさん主導で考案されて、今や標準規格となった緯度経度なんかの地理情報を表すフォーマットです。Google　Earthなんかも使ってま [...]]]></description>
			<content:encoded><![CDATA[<p>わけあって、<strong>KMLをJavascript</strong>で読み込んだりしていた。</p>
<p>KMLとは、<strong>Googleさん主導で考案されて、今や標準規格となった緯度経度なんかの地理情報を表すフォーマット</strong>です。Google　Earthなんかも使ってます。</p>
<p>で、<strong>XMLHttpRequest</strong>でKMLを読み込んで、<strong>取得した緯度経度列を画面上にプロット</strong>するまでは簡単だったんだけど、Firefox限定でなにかおかしい。や、XMLHｔｔｐRequestって時点でFirefoxというか非IEなんだけども。</p>
<p>この時はIEとFirefoxで確認していたんだけど、GoogleEarthで作成したKMLが、IEだと最後まで表示されているのだけど、<strong>Firefoxでは途中までしか表示できない</strong>。</p>
<p>ちなみに、IE側での描画はVML、FirefoxはCANVASでやっていたんだけど、どうやってもFirefoxが最後まで描画できない。</p>
<p>どうも座標数が増えると描画できないようなので、じゃあいくつまで表示できてるのよ、と数を数えてみると、<strong>きっちり４０９６bytes</strong>。どう考えてもあやしい。あやしすぎる。</p>
<p><span id="more-3809"></span></p>
<p>IEでは表示されてるからKMLには問題ない。ということはFirefoxでは4096byteまでしか取得できないとかいうはてなな仕様なのかも、と思ったら<strong>どうやらそのとおりらしい</strong>。まじすか。</p>
<p>正確には、<strong>4096byteを超えると、それ以降は勝手にノードが分割されて格納される</strong>らしい。</p>
<p>つまり取得時にfirstNode.nodeValueに格納すれば本来済むところを、</p>
<blockquote><p>childNodes[n].nodeValue</p></blockquote>
<p>n=byte数/4096ということなっているというザマ。超めんどくせーお話。</p>
<p>今までXMLを読んでるときはあんまり４０９６を超えないから気がつかなかったけど、KMLで扱うのは座標列なんで、座標数１００をこえれば、まあだいたい4096byteの上限だ。</p>
<p>手っ取り早く読み込むためにここでnormalizeしてあげる。</p>
<blockquote><p>xmldoc =xmlhttp.responseXML;<br />
if (typeof(xmldoc.normalize) != &#8220;undefined&#8221;) {<br />
<strong>xmldoc.normalize();</strong><br />
}</p></blockquote>
<p>こんな感じで書いたら、無事４０９６byte以降も読み込まれました。</p>
<p>ｎormalizeってのは要するに、同階層のノードをひとまとめにするものだけど、本来１ノードであるものをFirefoxが勝手に分割しちゃってるのに、それをこちらで尻拭いのようにnormarizeするのはなんだかなあ、と思わないでもないけど、読めなきゃしかたがない。</p>
<p>なので、一塊がめちゃめちゃ長いXMLやKMLをFirefoxで読み込む時はnormalizeをするってのがお約束。ひとつ学んだね。テストでるよ？でないけど。</p>
<p>ところで未確認なのだけれど、4096byteを超えても、<strong>jsonだと問題ない</strong>らしい。どんだけやねん。</p>
]]></content:encoded>
			<wfw:commentRss>http://hmlab.info/minor/2008/12/20081222_1226593809/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://hmlab.info/minor/2008/12/20081222_1226593809/" />
	</item>
	</channel>
</rss>

