<?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>~ overflow ~ &#187; dom</title>
	<atom:link href="http://www.overflow.biz/blog/lang/en-us/tag/dom/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.overflow.biz/blog</link>
	<description>Coding and Internet Randomness</description>
	<lastBuildDate>Sun, 08 Jan 2012 23:34:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en-us</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery + XML + IE = xmlDOM issue &#8230; or no??</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2009/08/29/jquery-xml-ie-xmldom-issue-or-no?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=jquery-xml-ie-xmldom-issue-or-no</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2009/08/29/jquery-xml-ie-xmldom-issue-or-no#comments</comments>
		<pubDate>Sat, 29 Aug 2009 19:52:41 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Notes]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xmldom]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=215</guid>
		<description><![CDATA[Problem:
In the middle of the developing of a very complex script i figured out that IE was simply ignoring the xml documents i sent to it by ajax. Searching the web i&#8217;ve found this $.xmlDOM jQuery extension that is supposed to fix the IE issue with xmls. Although the extesion was clear and other people [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>In the middle of the developing of a very complex script i figured out that IE was simply ignoring the xml documents i sent to it by ajax. Searching the web i&#8217;ve found <a href="http://outwestmedia.com/jquery-plugins/xmldom/" target="_blank">this $.xmlDOM jQuery extension</a> that is supposed to fix the IE issue with xmls. Although the extesion was clear and other people claims it work, it didn&#8217;t worked for me, how lucky is that?</p>
<p><strong>Solution:</strong></p>
<p>This took a while to solve, and i will skip all the boring process. Turns out that i didn&#8217;t needed the $.xmlDOM extension at all, the issue was on the xml. I&#8217;m developing this script in a language that has accents, i need to use `&#38;aacute;` like html entities in order to avoid malfuncioning with data transport, so this little ampersand was breaking IE.</p>
<p>How nice is that?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2009/08/29/jquery-xml-ie-xmldom-issue-or-no/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep it simple, stupid jQuery experience</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2009/08/14/keep-it-simple-stupid-jquery-experience?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=keep-it-simple-stupid-jquery-experience</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2009/08/14/keep-it-simple-stupid-jquery-experience#comments</comments>
		<pubDate>Fri, 14 Aug 2009 03:07:15 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Notes]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[issues]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.overflow.biz/blog/?p=185&amp;lang=en-us</guid>
		<description><![CDATA[As much as I like jQuery I must admit that it’s far away from simplifying things. Although it might be a great idea using it on 100% jQuery scripts, it’s a real bad idea using it to refurbish an old script.
Today I’ve spent over 2 hours implement jQuery on a old script I have, and [...]]]></description>
			<content:encoded><![CDATA[<p><span>As much as I like jQuery I must admit that it’s far away from simplifying things. Although it might be a great idea using it on 100% jQuery scripts, it’s a real bad idea using it to refurbish an old script.</span></p>
<p><span>Today I’ve spent over 2 hours implement jQuery on a old script I have, and I felt into so many issues that it didn’t worth at all.</span></p>
<p><span>My script was simple, I had a huge variable list that could be edited by a form, script loops through the variables building a form with input fields for each variable. I will not get into specific details because it’s boring, but I needed to allow the user to add a new variable inside an array, so i thought that jQuery would help a lot since i only would need to dynamic add a new input field as needed then post everything back to script to save the file.</span></p>
<p><span>First I spent an hour figuring out that jQuery was ruining the text by converting the whole thing into UTF-8, loosing all the accents, eventually I found out about contentType encoding ajax variable:</span></p>
<pre class="prettyprint"><code><span><strong><span class="pln">contentType</span><span class="pun">:</span><span class="str">"application/json; charset=utf-8"</span></strong></span></code></pre>
<pre class="prettyprint"><code><span class="str"><span>which could be changed to the charset i wanted.</span></span></code></pre>
<p><span>It was useless, jQuery still posting into the wrong charset, there’s some other tweks on this, but they are also useless.</span></p>
<p><span>I was able to fix the accent issue with this php statement:</span></p>
<p><span><strong>mb_convert_encoding(urldecode($variable),&#8221;ISO-8859-1&#8243;,&#8221;auto&#8221;);</strong></span></p>
<p><span>This is much more obscure though, but I was familiar with it since i coded in japanese charsets which are a pain to convert.</span></p>
<p><span>After having this cleared, and searching a lot of useless blogs and postings, turns out that jQuery was using the hard coded form names to post the data, which could be overlapped by an dynamic added field, I did a script to change the name of the hard coded inputs, something like this:</span></p>
<p><span><strong>$(&#8220;#field_id&#8221;).attr(’name’,’new_name’);</strong></span></p>
<p><span>Theorically, it worked, but when I did:</span></p>
<p><span><strong>$(&#8220;#form&#8221;).serialize();</strong></span></p>
<p><span>jQuery used the dynamic fields with the ordinary hard coded ignoring the attr changes.</span></p>
<p><span>Now I had to add a handler to dynamic convert and read all the inputs and do my own serialize in order to TRY to make it work&#8230;and that’s because i didn’t tested it on IE yet.</span></p>
<p><span>So that’s when I quit using jQuery for this script and do something plain and simple, which took me about 20 minutes and 0 searches.</span></p>
<p><span>It looks like that if I had used DOM elements for the whole form, all elements generated by jQuery itself, not hard coded, i would have less trouble with the form, although, the charset issues still.</span></p>
<p><span><strong>Super Fun Sources:</strong></span></p>
<p><span><a href="http://stahttp://stackoverflow.com/questions/26620/how-to-set-encoding-in-getjson-jqueryblank">Stack overflow posting</a></span></p>
<p><span><a href="http://stahttp://stackoverflow.com/questions/965150/jquery-ajax-post-and-encodingblank">Stack overflow posting 2</a></span></p>
<p><span><a href="http://dochttp://docs.jquery.com/Ajax/jQuery.ajax#optionsblank">jQuery Ajax Documentation</a> (completly useless since contentType explanation has 2 lines)</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2009/08/14/keep-it-simple-stupid-jquery-experience/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Google Search &#8220;API&#8221; by PHP (No API Needed)</title>
		<link>http://www.overflow.biz/blog/lang/en-us/2009/06/16/custom-google-search-api-by-php-no-api-needed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=custom-google-search-api-by-php-no-api-needed</link>
		<comments>http://www.overflow.biz/blog/lang/en-us/2009/06/16/custom-google-search-api-by-php-no-api-needed#comments</comments>
		<pubDate>Wed, 17 Jun 2009 02:16:52 +0000</pubDate>
		<dc:creator>z3n</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php-dom]]></category>
		<category><![CDATA[search]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://overflow.biz/blog/?p=154</guid>
		<description><![CDATA[



Problem:
I was looking for an API to do searches by google using a custom made php script, so i could display the results the way i want. I found out about a google search api that work with SOAP, however it&#8217;s been deprected and they only have the useless AJAX option, which don&#8217;t really serve [...]]]></description>
			<content:encoded><![CDATA[



<p><span lang="en-us"><strong>Problem:</strong></span></p>
<p><span lang="en-us">I was looking for an API to do searches by google using a custom made php script, so i could display the results the way i want. I found out about a <em>google search api</em> that work with SOAP, however it&#8217;s been deprected and they only have the useless AJAX option, which don&#8217;t really serve my propouse since the searches would be client-side processed at AJAX, and i needed them server-side processed.</span></p>
<p><span lang="en-us"><strong>Solution:</strong></span></p>
<p><span lang="en-us">This might looks like a hack, but there&#8217;s nothing much else we can do, although, for me, it was much easier than doing the research on the original api and finally finding out it was deprected. This PHP script will do a regular request to google, then it will process the data using DOM, cut it removing google ads and other crap, and finally return only the urls of the search. This will also make you able to search on country specific google, just change the domain and filter to get the results you want.</span></p>
<p><span lang="en-us">So here&#8217;s the PHP source that don&#8217;t depend on google happyness to work:</span></p>
<div class="geshi no php">
<div class="head">// (c) z3n &#8211; R1V1@090616 &#8211; z3n666@gmail.com &#8211; www.overflow.biz</div>
<ol>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re1">$argv</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">echo</span> <span class="st0">&#34;Usage: &#34;</span><span class="sy0">.</span><span class="re1">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#39;PHP_SELF&#39;</span><span class="br0">&#93;</span><span class="sy0">.</span><span class="st0">&#34; &#160;[start]&#34;</span><span class="sy0">;</span>die<span class="sy0">;</span> <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span> <span class="re1">$s</span><span class="sy0">=</span><span class="re1">$argv</span><span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy0">;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$e</span><span class="sy0">=</span><span class="br0">&#40;</span><span class="kw3">isset</span><span class="br0">&#40;</span><span class="re1">$argv</span><span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> ? <span class="st0">&#34;&#38;amp;start=&#34;</span><span class="sy0">.</span><span class="re1">$argv</span><span class="br0">&#91;</span><span class="nu0">2</span><span class="br0">&#93;</span> <span class="sy0">:</span> <span class="st0">&#34;&#34;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$x</span><span class="sy0">=</span><span class="kw3">file_get_contents</span><span class="br0">&#40;</span><span class="st0">&#34;http://www.google.com/search?q=&#34;</span><span class="sy0">.</span><span class="re1">$s</span><span class="sy0">.</span><span class="st0">&#34;&#38;amp;num=100&#34;</span><span class="sy0">.</span><span class="re1">$e</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// apply DOM</span></div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$dom</span><span class="sy0">=</span><span class="kw2">new</span> DOMDocument<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">@</span><span class="re1">$dom</span><span class="sy0">-&#38;</span>gt<span class="sy0">;</span>loadHTML<span class="br0">&#40;</span><span class="re1">$x</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$xpath</span><span class="sy0">=</span><span class="kw2">new</span> DOMXPath<span class="br0">&#40;</span><span class="re1">$dom</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$a</span><span class="sy0">=</span><span class="re1">$xpath</span><span class="sy0">-&#38;</span>gt<span class="sy0">;</span>evaluate<span class="br0">&#40;</span><span class="st0">&#34;/html/body//a&#34;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="br0">&#40;</span><span class="re1">$i</span><span class="sy0">=</span><span class="re1">$k</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span><span class="re1">$i</span><span class="sy0">&#38;</span>lt<span class="sy0">;</span><span class="re1">$a</span><span class="sy0">-&#38;</span>gt<span class="sy0">;</span>length<span class="sy0">;</span><span class="re1">$i</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;<span class="re1">$y</span><span class="sy0">=</span><span class="re1">$a</span><span class="sy0">-&#38;</span>gt<span class="sy0">;</span>item<span class="br0">&#40;</span><span class="re1">$i</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;<span class="re1">$z</span><span class="sy0">=</span><span class="re1">$y</span><span class="sy0">-&#38;</span>gt<span class="sy0">;</span>getAttribute<span class="br0">&#40;</span><span class="st0">&#39;href&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;<span class="co1">// filter out google crap, wikipedia and youtube</span></div>
</li>
<li class="li1">
<div class="de1">&#160;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="br0">&#40;</span><span class="re1">$z</span><span class="br0">&#123;</span><span class="nu0">0</span><span class="br0">&#125;</span> <span class="sy0">!=</span> <span class="st0">&#34;/&#34;</span><span class="br0">&#41;</span> <span class="sy0">&#38;</span>amp<span class="sy0">;&#38;</span>amp<span class="sy0">;</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$z</span><span class="sy0">,</span><span class="st0">&#34;q=cache:&#34;</span><span class="br0">&#41;</span> <span class="sy0">===</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="sy0">&#38;</span>amp<span class="sy0">;&#38;</span>amp<span class="sy0">;</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$z</span><span class="sy0">,</span><span class="st0">&#34;youtube.com/&#34;</span><span class="br0">&#41;</span> <span class="sy0">===</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="sy0">&#38;</span>amp<span class="sy0">;&#38;</span>amp<span class="sy0">;</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$z</span><span class="sy0">,</span><span class="st0">&#34;wikipedia.org/&#34;</span><span class="br0">&#41;</span> <span class="sy0">===</span> <span class="kw2">false</span><span class="br0">&#41;</span> <span class="sy0">&#38;</span>amp<span class="sy0">;&#38;</span>amp<span class="sy0">;</span> <span class="br0">&#40;</span><span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$z</span><span class="sy0">,</span><span class="st0">&#34;.google.com/&#34;</span><span class="br0">&#41;</span> <span class="sy0">===</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&#160; <span class="re1">$_url</span><span class="br0">&#91;</span><span class="re1">$k</span><span class="br0">&#93;</span><span class="sy0">=</span><span class="re1">$z</span><span class="sy0">;</span><span class="re1">$k</span><span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&#160;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">print_r</span><span class="br0">&#40;</span><span class="re1">$_url</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&#34;Found: &#34;</span><span class="sy0">.</span><span class="re1">$k</span><span class="sy0">.</span><span class="st0">&#34; urls.&#34;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p><span lang="en-us">* Note: You need DOM Object support in order to run this script; This example has been developed to accept input from the CLI, you can easly change it to work inside your script or/and accept $_GET or $_POST.</span></p>
<p><span lang="en-us"><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.overflow.biz/blog/lang/en-us/2009/06/16/custom-google-search-api-by-php-no-api-needed/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

