<?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>yesJames.com &#187; internet</title>
	<atom:link href="http://www.yesjames.com/index.php/tag/internet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.yesjames.com</link>
	<description>ahuh... sure... what ever you say...</description>
	<lastBuildDate>Fri, 13 Nov 2009 02:59:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Firefox compatible xPath functions in JavaScript</title>
		<link>http://www.yesjames.com/index.php/2008/11/firefox-compatible-xpath-functions-in-javascript/</link>
		<comments>http://www.yesjames.com/index.php/2008/11/firefox-compatible-xpath-functions-in-javascript/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 01:41:27 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[XPath]]></category>

		<guid isPermaLink="false">http://www.yesjames.com/?p=74</guid>
		<description><![CDATA[There are a lot of quirks between different browsers, in particular though are the differences in the way each browser handles the DOM in JavaScript.
Internet Explorer, for the most part, implements MSXml 4.0 or higher. However that&#8217;s (obviously) a Microsoft technology, and the standard implementation doesn&#8217;t support XPath in the DOM.
In particular the selectNodes() and [...]]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript" language="javascript" src="http://www.yesjames.com/wp-content/themes/yesjames_blue/sh/shBrushXml.js"></script>There are a lot of quirks between different browsers, in particular though are the differences in the way each browser handles the DOM in JavaScript.</p>
<p>Internet Explorer, for the most part, implements MSXml 4.0 or higher. However that&#8217;s (obviously) a Microsoft technology, and the standard implementation doesn&#8217;t support XPath in the DOM.</p>
<p>In particular the <strong>selectNodes()</strong> and <strong>selectSingleNode()</strong> functions are of particular use when manipulating XML or the DOM. Using these functions you can parse an XPath expression and get a nodelist of elements in your DOM that match the expression.</p>
<p><span id="more-74"></span></p>
<p>The code below adds basic XPath parsing functionality to the DOM in Mozilla. (Thanks to km0ti0n)</p>
<pre name="code" class="javascript">
// mozXPath - http://km0.la/js/mozXPath/
// km0ti0n@gmail.com
// Code licensed under Creative Commons Attribution-ShareAlike License
// http://creativecommons.org/licenses/by-sa/2.5/
if (document.implementation.hasFeature("XPath", "3.0")) {
	if ( typeof XMLDocument == "undefined" ) {
		XMLDocument = Document;
	}
	XMLDocument.prototype.selectNodes = function(cXPathString, xNode) {
		if ( !xNode ) { xNode = this; }
		var oNSResolver = this.createNSResolver(this.documentElement);
		var aItems = this.evaluate(cXPathString, xNode, oNSResolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
		var aResult = [];
		for ( var i = 0; i < aItems.snapshotLength; i++) {
			aResult[i] =  aItems.snapshotItem(i);
		}
		return aResult;
	}
	XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode) {
		if( !xNode ) { xNode = this; }
		var xItems = this.selectNodes(cXPathString, xNode);
		if ( xItems.length > 0 ) { return xItems[0]; }
		else { return null; }
	}

	Element.prototype.selectNodes = function(cXPathString) {
		if (this.ownerDocument.selectNodes) {
			return this.ownerDocument.selectNodes(cXPathString, this);
		} else { throw "For XML Elements Only"; }
	}

	Element.prototype.selectSingleNode = function(cXPathString) {
		if (this.ownerDocument.selectSingleNode) {
			return this.ownerDocument.selectSingleNode(cXPathString, this);
		} else { throw "For XML Elements Only"; }
	}
}
</pre>
<p>It appears that Opera doesn&#8217;t have the XMLDocument object type, so, when using the XmlHttpRequest object the <em>responseXML</em> is in fact a <em>Document</em> object.</p>
<p>To get around this fact, we can use:</p>
<pre name="code" class="javascript">
if ( typeof XMLDocument == "undefined" ) {
    XMLDocument = Document;
}
</pre>
<p>To use these new features, in either IE or Firefox, you can now simple call the functions as a method of the elements themselves&#8230; e.g.:</p>
<p>On the following XML Document:</p>
<pre name="code" class="xml">
<MainNode>
    <SubNode id="1" enabled="true">
      <ContentNode>Some Content</ContentNode>
    </SubNode>
    <SubNode id="2" enabled="true">
      <ContentNode>Some Content</ContentNode>
    </SubNode>
    <SubNode id="3" enabled="false">
      <ContentNode>Some Content</ContentNode>
    </SubNode>
</MainNode>
</pre>
<p>For the XML sample above, you can use the following XPath to select all <em>ContentNode</em>&#8217;s with their <em>enabled</em> attribute set to <em>&#8220;true&#8221;</em>:<br />
<code>//subnode[@enabled='true']/contentnode</code></p>
<p>So you would retrieve your XML Node List by executing the following JavaScript function:</p>
<pre name="code" class="javascript">
//assume the variable xDOM is an XmlDocument object
//...that has been pre-loaded with the example XML
var nodeList = xDOM.selectNodes('//subnode[@enabled='true']/contentnode');
for each (var xNode in nodeList) {
    //do some operation...
}
</pre>
<p>This would perform some operation on each <em>contentnode</em> which is inside a <em>subnode</em> with it&#8217;s <em>enabled</em> property set to <em>true</em>.</p>
<p><em><strong>NOTE:</strong> Be sure to double check your syntax, spelling and remember XML/XPath is CaseSensitive.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yesjames.com/index.php/2008/11/firefox-compatible-xpath-functions-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>howto: Format numbers in JavaScript</title>
		<link>http://www.yesjames.com/index.php/2008/11/howto-format-numbers-in-javascript/</link>
		<comments>http://www.yesjames.com/index.php/2008/11/howto-format-numbers-in-javascript/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 23:17:32 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[web programming]]></category>

		<guid isPermaLink="false">http://www.yesjames.com/?p=41</guid>
		<description><![CDATA[Formatting Numbers
Numeric formatting in JavaScript can be very tedious. From handling non-numeric characters, to multiple-currency symbols, to alternate negative display methods. The functions below should be valuable in assisting to format numbers and currencies of all types.

To do complete formatting of a number, the following function formatNumber(), takes several parameters specifying the properties of the [...]]]></description>
			<content:encoded><![CDATA[<h3>Formatting Numbers</h3>
<p>Numeric formatting in JavaScript can be very tedious. From handling non-numeric characters, to multiple-currency symbols, to alternate negative display methods. The functions below should be valuable in assisting to format numbers and currencies of all types.</p>
<p><span id="more-41"></span></p>
<p>To do complete formatting of a number, the following function <b>formatNumber()</b>, takes several parameters specifying the properties of the output.</p>
<pre name="code" class="javascript">
/* formatNumber: PARAMETERS...
num: the decimal number to convert (must be numeric)
dec: number of resulting decimal places to keep
thou: the character to use for thousands separator
pnt: the character to use for decimal point
curr1: Preceding Currency Symbol
curr2: Trailing Currency symbol
n1: Preceding Negative character
n2: Trailing Negative character
*/
function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2) {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1 = n2 = '';
	var y = (''+ Math.abs(x)).split('');
	var z = y.length - dec;
	if (z<0) z--;
	for (var i = z; i < 0; i++) y.unshift('0');
	if (z<0) z = 1;
	y.splice(z, 0, pnt);
	if (y[0] == pnt) y.unshift('0');
	while (z > 3) { z-=3; y.splice(z,0,thou); }
	var r = curr1 + n1 + y.join('') + n2 + curr2;
	return r;
}
</pre>
<p>To use this function, simply call the function with the parameters you require.<br />
e.g. To display a currency (western such as USD or AUD):</p>
<pre name="code" class="javascript">
var cur = formatNumber(1257.45, 2, ',', '.', '$', '', '-', '');
alert(cur);
</pre>
<p>will output: <b>$1,257.45</b></p>
<p>Alternatively, you may decide to use a helper function that defaults most of these values for you. For example:</p>
<pre name="code" class="javascript">
function formatCurrency(num) {
  return formatNumber(num, 2, ',', '.', '$', '', '-', '');
}
</pre>
<p>The thousandsFormat() function takes any decimal number, negative or positive, and formats it by adding commas every three digits. This makes the number more readable for your site visitors:</p>
<pre name="code" class="javascript">
// This function formats numbers by adding commas
function thousandsFormat(nStr) {
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length &gt; 1 ? '.' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1))
    x1 = x1.replace(rgx, '$1' + ',' + '$2');
  return x1 + x2;
}
</pre>
<h2>Strip Non-Numeric Characters From a String</h2>
<p>The stripNonNumeric() function strips any non-numeric characters from a string leaving you with a valid decimal number. This function considers the minus sign (hyphen) and the period to be numeric and will not strip them unless the minus sign is not at the beginning of the number or there is more than one period:</p>
<pre name="code" class="javascript">
// This function removes non-numeric characters
function stripNonNumeric(str) {
  str += '';
  var rgx = /^\d|\.|-$/;
  var out = '';
  for (var i = 0; i < str.length; i++) {
    if (rgx.test(str.charAt(i))) {
      if (!((str.charAt(i)=='.' &#038;&#038; out.indexOf('.')!=-1)
        || (str.charAt(i)=='-' &#038;&#038;  out.length!=0))) {
        out += str.charAt(i);
      }
    }
  }
  return out;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.yesjames.com/index.php/2008/11/howto-format-numbers-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>howto: GET a URL parameter in JavaScript</title>
		<link>http://www.yesjames.com/index.php/2008/02/howto-get-a-url-parameter-in-javascript/</link>
		<comments>http://www.yesjames.com/index.php/2008/02/howto-get-a-url-parameter-in-javascript/#comments</comments>
		<pubDate>Mon, 11 Feb 2008 09:38:01 +0000</pubDate>
		<dc:creator>james</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[get parameter]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[parameters]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[url parameter]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.yesjames.com/index.php/2008/02/11/howto-get-a-url-parameter-in-javascript/</guid>
		<description><![CDATA[A useful little piece of JavaScript for retrieving a URL parameter (Query String) from your page. If a requested parameter doesn&#8217;t exist it will return an empty string rather than a NULL object. It will also handle the inclusion of anchor tags in the URL and exclude them from possible results.
e.g. http://www.yesjames.com/test.php?myparam=justatest
calling &#8220;gerURLParam(&#8216;myparam&#8217;) will return [...]]]></description>
			<content:encoded><![CDATA[<p>A useful little piece of JavaScript for retrieving a URL parameter (Query String) from your page. If a requested parameter doesn&#8217;t exist it will return an empty string rather than a NULL object. It will also handle the inclusion of anchor tags in the URL and exclude them from possible results.</p>
<blockquote><p>e.g. http://www.yesjames.com/test.php?myparam=justatest<br />
calling &#8220;gerURLParam(&#8216;myparam&#8217;) will return &#8220;justatest&#8221;</p></blockquote>
<pre name="code" class="javascript">
function getURLParam(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var pattern = "[\\?&amp;]"+name+"=([^&amp;#]*)";
  var regex = new RegExp(pattern);
  var aResult = regex.exec(window.location.href);
  if ( aResult == null ) {
    return "";
  } else {
    return aResult[1];
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.yesjames.com/index.php/2008/02/howto-get-a-url-parameter-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
