<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3" -->
<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/"
	>

<channel>
	<title>Two's-Complement</title>
	<link>http://www.twoscomplement.com</link>
	<description>A couple who code for a living</description>
	<pubDate>Wed, 22 Oct 2008 22:15:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3</generator>
	<language>en</language>
			<item>
		<title>Floating in the Pre-Css Era</title>
		<link>http://www.twoscomplement.com/2008/10/22/floating-in-the-pre-css-era/</link>
		<comments>http://www.twoscomplement.com/2008/10/22/floating-in-the-pre-css-era/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 22:15:48 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[HTML]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[align]]></category>

		<category><![CDATA[br]]></category>

		<category><![CDATA[clear]]></category>

		<category><![CDATA[float]]></category>

		<category><![CDATA[table]]></category>

		<guid isPermaLink="false">http://www.twoscomplement.com/2008/10/22/floating-in-the-pre-css-era/</guid>
		<description><![CDATA[Today I learned a fact about HTML which had somehow alluded me for many years. Having been working on web-related projects for so long, the mind boggles as to how I could possibly have not picked up on this in all that time.
With CSS, one can use the float property to make text flow to [...]]]></description>
			<content:encoded><![CDATA[<p>Today I learned a fact about HTML which had somehow alluded me for many years. Having been working on web-related projects for so long, the mind boggles as to how I could possibly have not picked up on this in all that time.</p>
<p>With CSS, one can use the <i>float</i> property to make text flow to the left or to the right of an element rather than have the element occupy the entire row.</p>
<p>But what I hadn&#8217;t realised until today was that the <i>align</i> attribute (that&#8217;s the plain old HTML attribute, not a CSS property) of the <i>table</i> element can be used to the same effect. Setting the attribute to &#8220;left&#8221; or &#8220;right&#8221; will float the table to the left or right respectively. So, for example, three left-aligned tables will follow each other on the same line rather than being rendered vertically one below the other:</p>
<p><code>&lt;table <b>align="left"</b> border="1"&gt;<br />
	&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;<br />
	&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;table <b>align="left"</b> border="1"&gt;<br />
	&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;<br />
	&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;<br />
&lt;/table&gt;<br />
&lt;table <b>align="left"</b> border="1"&gt;<br />
	&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;<br />
	&lt;tr&gt;&lt;td&gt;foo&lt;/td&gt;&lt;td&gt;bar&lt;/td&gt;&lt;/tr&gt;<br />
&lt;/table&gt;</code></p>
<table align="left" border="1">
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</table>
<table align="left" border="1">
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</table>
<table align="left" border="1">
<tr>
<td>foo</td>
<td>bar</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
</tr>
</table>
<p><br clear="all" /></p>
<p>And the <i>clear</i> attribute of the <i>br</i> tag can be used to do the same thing as the <i>clear</i> CSS property would: force the following text to start below, undoing the effect of floating:</p>
<p><code>&lt;br clear="all"&gt;</code></p>
<p>It&#8217;s a feature of HTML which has little purpose these days, what with CSS being the preferred way to change the presentation of page elements, but it&#8217;s nice to know about nonetheless.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/10/22/floating-in-the-pre-css-era/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An introduction to friendly URLs in PHP</title>
		<link>http://www.twoscomplement.com/2008/06/22/an-introduction-to-friendly-urls-in-php/</link>
		<comments>http://www.twoscomplement.com/2008/06/22/an-introduction-to-friendly-urls-in-php/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 12:47:22 +0000</pubDate>
		<dc:creator>Fiona</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[RegEx]]></category>

		<category><![CDATA[apache]]></category>

		<category><![CDATA[friendly urls]]></category>

		<category><![CDATA[htaccess]]></category>

		<category><![CDATA[mod_rewrite]]></category>

		<category><![CDATA[readable urls]]></category>

		<category><![CDATA[regular expressions]]></category>

		<category><![CDATA[url]]></category>

		<category><![CDATA[urls]]></category>

		<guid isPermaLink="false">http://www.twoscomplement.com/2008/06/22/an-introduction-to-friendly-urls-in-php/</guid>
		<description><![CDATA[Nice URLs, readable URLs, search-engine-friendly URLs. Different names same deal.
It can&#8217;t really be disagreed on that something like example.com/index.php?page=article&#38;id=409 is not nearly as nice as example.com/article/409.
Turns out this isn&#8217;t all that hard with PHP - infact it can turn into something that&#8217;s very useful from more than just a readability viewpoint.
The Plan
What we&#8217;re going to [...]]]></description>
			<content:encoded><![CDATA[<p>Nice URLs, readable URLs, search-engine-friendly URLs. Different names <a href="http://en.wikipedia.org/wiki/Rewrite_engine">same deal</a>.</p>
<p>It can&#8217;t really be disagreed on that something like <strong>example.com/index.php?page=article&amp;id=409</strong> is not nearly as nice as <strong>example.com/article/409</strong>.</p>
<p>Turns out this isn&#8217;t all that hard with <a href="http://www.php.net">PHP</a> - infact it can turn into something that&#8217;s very useful from more than just a readability viewpoint.</p>
<h1>The Plan</h1>
<p>What we&#8217;re going to do is capture everything past a particular point in our URL and pipe it to PHP, we&#8217;re going to let PHP do most of the the legwork.</p>
<ul>
<li>Using <a href="http://httpd.apache.org/docs/2.2/rewrite/">mod_rewrite</a> we get everything past a particular point.</li>
<li>We will then pass that into a PHP get variable. We&#8217;ll use &#8220;p&#8221;, you can use anything.</li>
<li>In our PHP we will define &#8220;rules&#8221; for our URLs with very simple regular expressions.</li>
<li>When something matches, we&#8217;ll get the appropriate page - otherwise we&#8217;ll give back a 404.</li>
</ul>
<p> <a href="http://www.twoscomplement.com/2008/06/22/an-introduction-to-friendly-urls-in-php/#more-23" class="more-link">(more&#8230;)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/06/22/an-introduction-to-friendly-urls-in-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IE6 z-index bug</title>
		<link>http://www.twoscomplement.com/2008/06/16/ie6-z-index-bug/</link>
		<comments>http://www.twoscomplement.com/2008/06/16/ie6-z-index-bug/#comments</comments>
		<pubDate>Mon, 16 Jun 2008 17:10:44 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[Browser Quirks]]></category>

		<category><![CDATA[browser quirk]]></category>

		<category><![CDATA[css]]></category>

		<category><![CDATA[ie6]]></category>

		<category><![CDATA[internet explorer]]></category>

		<category><![CDATA[stacking context]]></category>

		<category><![CDATA[w3c]]></category>

		<category><![CDATA[z-index]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2008/06/16/ie6-z-index-bug/</guid>
		<description><![CDATA[I ran into an IE6 bug the other day which I&#8217;ve encountered a few times
before and managed to workaround without really knowing the true
cause. This time I decided to look into what was actually going on.
The problem is the way IE6 treats the z-index css property.
According to the W3C spec, the order in which page [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into an IE6 bug the other day which I&#8217;ve encountered a few times<br />
before and managed to workaround without really knowing the true<br />
cause. This time I decided to look into what was actually going on.</p>
<p>The problem is the way IE6 treats the <i>z-index</i> css property.</p>
<p>According to the W3C spec, the order in which page elements are drawn<br />
is determined by their position within their surrounding <i>stacking<br />
context</i>. The page itself is the outermost stacking context, and by<br />
default page elements are positioned in the order in which they appear<br />
in the document. Their <i>z-index</i> is effectively zero:</p>
<pre>
html
  |- head           (0) }
  '- body           (0) }
       |- div1      (0) } stacking
       |    |- div2 (0) } context
       |    '- div3 (0) }
       '- div4      (0) }
</pre>
<p>When the <i>z-index</i> css property is applied to an element, this<br />
does 2 things. Firstly it specifies where that element should be<br />
positioned within its surrounding stacking context. A lower index puts<br />
the element behind the others, and a higher one ensures that the<br />
element will be drawn infront of the others. The z-index property also<br />
creates a new stacking context in which its index is zero. The order<br />
in which this element&#8217;s children are drawn will be determined by this<br />
new stacking context:</p>
<pre>
html
  |- head                          (0) }
  '- body                          (0) }
       |- div1 [z-index: 2]  (0) } (2) }
       |    |- div2          (0) }     }
       |    '- div3          (0) }     }
       '- div4                     (0) }
</pre>
<p>Thus if our <i>div3</i> is given a z-index of -1:</p>
<pre>
html
  |- head                                (0) }
  '- body                                (0) }
       |- div1 [z-index: 2]       (0)  } (2) }
       |    |- div2               (0)  }     }
       |    '- div3 [z-index: -1] (-1) }     }
       '- div4                           (0) }
</pre>
<p>Then the rendering order would be:</p>
<p>html<br />
head<br />
body<br />
div4<br />
div3<br />
div1<br />
div2</p>
<p>The problem with IE6 is that when an element is given the css property<br />
<i>position: relative</i>, it establishes a new stacking context even<br />
if no z-index property has been set with it.</p>
<p>This is extremely annoying because it means that the children of a<br />
relatively positioned element can never be told to render below its<br />
previous siblings or above its subsequent siblings. You&#8217;re kind of<br />
&#8220;boxed in&#8221; to a range of z depths. The workaround? I guess to avoid<br />
using relative positioning, if possible.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/06/16/ie6-z-index-bug/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Multiple Dispatch and the Visitor Pattern</title>
		<link>http://www.twoscomplement.com/2008/06/14/multiple-dispatch-and-the-visitor-pattern/</link>
		<comments>http://www.twoscomplement.com/2008/06/14/multiple-dispatch-and-the-visitor-pattern/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 14:58:25 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[Code Design]]></category>

		<category><![CDATA[Design Patterns]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[Lisp]]></category>

		<category><![CDATA[multiple dispatch]]></category>

		<category><![CDATA[reflection]]></category>

		<category><![CDATA[single dispatch]]></category>

		<category><![CDATA[state machine]]></category>

		<category><![CDATA[visitor pattern]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2008/06/14/multiple-dispatch-and-the-visitor-pattern/</guid>
		<description><![CDATA[Following from my yakking about the state machine pattern, I&#8217;ve run into situations since where I&#8217;ve had a class which must react differently to different inputs, and thought how, rather than write a huge switch statement, or huge else-if with lots of instanceof tests, it would instead be nice to write methods which accept different [...]]]></description>
			<content:encoded><![CDATA[<p>Following from my <a href="http://blog.jankle.com/2007/10/12/state-machine-inputs/">yakking about the state machine pattern</a>, I&#8217;ve run into situations since where I&#8217;ve had a class which must react differently to different inputs, and thought how, rather than write a huge <i>switch</i> statement, or huge <i>else-if</i> with lots of <i>instanceof</i> tests, it would instead be nice to write methods which accept different types of object. And even better, to be able to hoist a catch-all method which accept the superclass of these objects into a superclass of my handler class:</p>
<pre>
public abstract class Handler
{
	public void handleInput(Input input)
	{
		// do nothing - just catch all Inputs not handled by subclass
	}
}

public abstract class Input
{}

public class AlphaInput extends Input
{}

public class BetaInput extends Input
{}

public class GammaInput extends Input
{}

public class MyHandler extends Handler
{
	public void handleInput(AlphaInput alpha)
	{
		//handle one kind of input here
	}

	public void handleInput(BetaInput beta)
	{
		//handle another kind of input here
	}
}

public class Main
{
	public static void main(String[] args)
	{
		Handler handler = new MyHandler();

		//handle an AlphaInput
		Input input = new AlphaInput();
		handler.handleInput(input);

		//handle a BetaInput
		input = new BetaInput();
		handler.handleInput(input);

		//handle a GammaInput - it can handle any subclass of Input because of the
		//catch-all method in the Handler superclass.
		input = new GammaInput();
		handler.handleInput(input);
	}
}
</pre>
<p><b>THIS WILL NOT WORK</b>. What will happen here is that <b>all three</b> inputs will be handled the same way. They will all be swallowed up by the catch-all in the <i>Handler</i> class, which accepts the <i>Input</i> type.</p>
<p>&#8220;Why not?&#8221;, you might ask. It turns out that Java, and likewise C++, are what are known as <i>single-dispatch</i> languages. A class method can be thought of as a function where the first parameter is the object which owns the method. For example, when we make the method call <i>handler.handleInput(input)</i>, this can be thought of as the function</p>
<pre>
handleInput(handler, input);
</pre>
<p>Java, as a single dispatch language, will examine at runtime the actual type of object that the first of these parameters is refering to (in this case, MyHandler), but will not do the same for subsequent parameters - it will use the type we referred to them by (in this case Input). Thus when finding the appropriate function to use, Java comes up with:</p>
<pre>
handleInput(MyHandler handler, Input input);
</pre>
<p>Java calls the method of MyHandler which accepts an Input - i.e. the one inheritted from Handler which does nothing. Other languages, such as Common Lisp, are known as multiple-dispatch languages because <b>all</b> the parameters&#8217; types are investigated at runtime.</p>
<p>Design patterns such as the Visitor pattern were invented to work around the limitation of single-dispatch in languages like Java. Patterns such as this basically boil down to the object being passed in as the parameter identifying its own type to the receiving object.</p>
<p>For example, the handler example could be improved by altering the code to look like this:</p>
<pre>
public abstract class Handler
{
	public <b>abstract</b> void handleInput(Input input);

	<b>public void handleAlphaInput(AlphaInput input)
	{
		// do nothing
	}</b>

	<b>public void handleBetaInput(BetaInput input)
	{
		// do nothing
	}</b>

	<b>public void handleGammaInput(GammaInput input)
	{
		// do nothing
	}</b>
}

public abstract class Input
{
	<b>public abstract void handleMe(Handler handler);</b>
}

public class AlphaInput extends Input
{
	<b>public void handleMe(Handler handler)
	{
		handler.handleAlphaInput(this);
	}</b>
}

public class BetaInput extends Input
{
	<b>public void handleMe(Handler handler)
	{
		handler.handleBetaInput(this);
	}</b>
}

public class GammaInput extends Input
{
	<b>public void handleMe(Handler handler)
	{
		handler.handleGammaInput(this);
	}</b>
}

public class MyHandler extends Handler
{
	<b>public void handleInput(Input input)
	{
		input.handleMe(this);
	}</b>

	public void <b>handleAlphaInput</b>(AlphaInput alpha)
	{
		//handle one kind of input here
	}

	public void <b>handleBetaInput</b>(BetaInput beta)
	{
		//handle another kind of input here
	}
}

public class Main
{
	public static void main(String[] args)
	{
		Handler handler = new MyHandler();

		//handle an AlphaInput
		Input input = new AlphaInput();
		handler.handleInput(input);

		//handle a BetaInput
		input = new BetaInput();
		handler.handleInput(input);

		//handle a GammaInput
		input = new GammaInput();
		handler.handleInput(input);
	}
}
</pre>
<p>We must create separate methods to handle alpha, beta and gamma inputs, and these may be optionally be overridden in subclasses of Handler. To decide which to invoke, each subclass of Handler must implement <i>handleInput(Input input)</i> and call <i>input.handleMe(this)</i> to get the subclass of Input to identify its runtime type, by calling the appropriate method and passing itself in. Its ugly, it means that adding new Input subclasses is extremely awkward, but its the best that Java has to offer without using reflection.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/06/14/multiple-dispatch-and-the-visitor-pattern/feed/</wfw:commentRss>
		</item>
		<item>
		<title>UTF-7 with JavaMail</title>
		<link>http://www.twoscomplement.com/2008/06/14/utf-7-with-javamail/</link>
		<comments>http://www.twoscomplement.com/2008/06/14/utf-7-with-javamail/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 11:58:57 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Protocols]]></category>

		<category><![CDATA[email]]></category>

		<category><![CDATA[encoding]]></category>

		<category><![CDATA[javamail]]></category>

		<category><![CDATA[pop3]]></category>

		<category><![CDATA[utf-7]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2008/06/14/utf-7-with-javamail/</guid>
		<description><![CDATA[Java has a pretty cool api for handling email called JavaMail. There are classes for constructing and sending multipart email as well as classes for connecting to mailboxes and processing the messages therein.
I hit a bit of a problem, however, when some of the emails in the pop3 mailbox I was trying to read threw [...]]]></description>
			<content:encoded><![CDATA[<p>Java has a pretty cool api for handling email called JavaMail. There are classes for constructing and sending multipart email as well as classes for connecting to mailboxes and processing the messages therein.</p>
<p>I hit a bit of a problem, however, when some of the emails in the pop3 mailbox I was trying to read threw <i>java.io.UnsupportedEncodingException: utf-7</i>. The problem was that the javamail api, while supporting a whole host of character encodings, didn&#8217;t support UTF-7. I hadn&#8217;t heard of this encoding before and thought maybe, as these were spam emails I was trying to read through, the sender had set a silly value in the header to try and throw off simple mail readers such as mine. However a quick visit to <a href="http://en.wikipedia.org/wiki/UTF-7">wikipedia</a> informed me that UTF-7 is a real encoding, albeit a rarely used one.</p>
<p>It appears that if you don&#8217;t want UTF-7 encoded email to break your mail reader, you have to decode it yourself. The encoding seems a little awkward but there is a solution <a href="http://archives.java.sun.com/cgi-bin/wa?A2=ind0105&#038;L=javamail-interest&#038;F=&#038;S=&#038;P=4568">on this mailing list.</a></p>
<p>For my purposes, however, it was sufficient to extract the text in an extremely quick and dirty way by reading the raw bytes from the message input stream and only writing out those which fell within the ascii character range (outputting a &#8220;?&#8221;, otherwise):</p>
<pre><code>private String cheapBodyExtract(InputStream input)
	throws IOException
{
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	int c;
	while((c = input.read()) != -1)
	{
		baos.write(c);
	}
	byte[] bytes = baos.toByteArray();
	for(byte b : bytes)
	{
		if(b &lt; 32 || b &gt; 127)
		{
			b = '?';
		}
	}

	return new String(bytes);
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/06/14/utf-7-with-javamail/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Doctype Declaration with XMLC</title>
		<link>http://www.twoscomplement.com/2008/03/23/doctype-declaration-with-xmlc/</link>
		<comments>http://www.twoscomplement.com/2008/03/23/doctype-declaration-with-xmlc/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 14:00:17 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[JSP]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[XMLC]]></category>

		<category><![CDATA[doctype]]></category>

		<category><![CDATA[dom]]></category>

		<category><![CDATA[domformatter]]></category>

		<category><![CDATA[enhydra]]></category>

		<category><![CDATA[outputoptions]]></category>

		<category><![CDATA[publicid]]></category>

		<category><![CDATA[systemid]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2008/03/23/doctype-declaration-with-xmlc/</guid>
		<description><![CDATA[Enhydra XMLC is a neat alternative to Java Server Pages (JSP). XMLC takes a page of plain old HTML and generates a java class capable of producing the same HTML. By marking important elements in the HTML with id and class tags beforehand, you can have XMLC generate accessor methods for these elements in the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.enhydra.org/tech/xmlc">Enhydra XMLC</a> is a neat alternative to Java Server Pages (JSP). XMLC takes a page of plain old HTML and generates a java class capable of producing the same HTML. By marking important elements in the HTML with id and class tags beforehand, you can have XMLC generate accessor methods for these elements in the resulting java class. In this way you can turn a static page of HTML into a dynamic java object which you can manipulate and then output in your code. Changes can be made to the design of the HTML and the java class re-generated with little to no change to your business logic.</p>
<p>To output the page, the <i>toDocument</i> method is called and written to the servlet response object:</p>
<pre>
resp.getWriter().write(page.toDocument());
</pre>
<p>However, in doing this you may find that the resulting page does not look the same as the original HTML, as the Doctype declaration will be missing from the start of the output, leaving the browser in quirks mode as it renders the page.</p>
<p>The lack of doctype is apparently by design, as it is not part of the DOM standard. XMLC does provide the means to add it back in, however, and that is the <i>DOMFormatter object</i> in <i>org.enhydra.xml.io</i>. DOMFormatter writes a DOM tree to an output stream and takes an <i>OutputOptions</i> class to specify various options for doing this. To add the doctype to the output, the public and system ids must be set in the OutputOptions class:</p>
<pre>
OutputOptions options = new OutputOptions();
options.setPublicId("-//W3C//DTD HTML 4.0 Transitional//EN");
options.setSystemId("http://www.w3.org/TR/REC-html40/loose.dtd");

DOMFormatter formatter = new DOMFormatter(options);
formatter.write(page.getDocument(), resp.getWriter());
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/03/23/doctype-declaration-with-xmlc/feed/</wfw:commentRss>
		</item>
		<item>
		<title>XML Attribute Namespaces</title>
		<link>http://www.twoscomplement.com/2008/03/16/xml-attribute-namespaces/</link>
		<comments>http://www.twoscomplement.com/2008/03/16/xml-attribute-namespaces/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 13:46:00 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2008/03/16/xml-attribute-namespaces/</guid>
		<description><![CDATA[When using namespaces in xml, the namespace of an element is, by
default, inherited by its child elements. For example:
&#60;Car xmlns="my-namespace-1"&#62;
    &#60;Engine /&#62;
    &#60;Wheels&#62;
        &#60;Wheel /&#62;
        &#60;Wheel /&#62;
        &#60;Wheel [...]]]></description>
			<content:encoded><![CDATA[<p>When using namespaces in xml, the namespace of an element is, by<br />
default, inherited by its child elements. For example:</p>
<pre><code>&lt;Car xmlns="my-namespace-1"&gt;
    &lt;Engine /&gt;
    &lt;Wheels&gt;
        &lt;Wheel /&gt;
        &lt;Wheel /&gt;
        &lt;Wheel /&gt;
        &lt;Wheel /&gt;
    &lt;/Wheels&gt;
&lt;/Car&gt;</code></pre>
<p>Here the <i>Car</i> element has the namespace &#8220;my-namespace-1&#8243; as<br />
defined by the <i>xmlns</i> attribute. The <i>Engine</i>,<br />
<i>Wheels</i> and each <i>Wheel</i> element all inherit the same<br />
namespace.</p>
<p>However it is worth nothing that the same does not apply to<br />
attributes. Attributes have no namespace unless they are prefixed -<br />
even if a namespace has been defined for their parent element.</p>
<p>For example:</p>
<pre><code>&lt;Car xmlns="my-namespace-1" <b>colour="blue"</b> &gt;
    &lt;Engine <b>cylinders="6"</b> /&gt;
    &lt;Wheels&gt;
        &lt;Wheel <b>tirepressure="ok"</b>/&gt;
        &lt;Wheel <b>tirepressure="ok"</b>/&gt;
        &lt;Wheel <b>tirepressure="ok"</b>/&gt;
        &lt;Wheel <b>tirepressure="low"</b>/&gt;
    &lt;/Wheels&gt;
&lt;/Car&gt;</code></pre>
<p>Here, the <i>cylinders</i> attribute on the <i>Engine</i>, the<br />
<i>tirepressure</i> on the <i>Wheel</i> elements and even the<br />
<i>colour</i> attribute on the <i>Car</i> - all of these belong to the<br />
default namespace rather than to &#8220;my-namespace-1&#8243;.</p>
<p>For these attributes to use that namespace, a prefix would have to be<br />
defined for them, for example:</p>
<pre><code>&lt;<b>ns:</b>Car <b>xmlns:ns="my-namespace-1"</b> <b>ns:</b>colour="blue" &gt;
    &lt;Engine <b>ns:</b>cylinders="6" /&gt;
    &lt;Wheels&gt;
        &lt;Wheel <b>ns:</b>tirepressure="ok" /&gt;
        &lt;Wheel <b>ns:</b>tirepressure="ok" /&gt;
        &lt;Wheel <b>ns:</b>tirepressure="ok" /&gt;
        &lt;Wheel <b>ns:</b>tirepressure="low" /&gt;
    &lt;/Wheels&gt;
&lt;/Car&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/03/16/xml-attribute-namespaces/feed/</wfw:commentRss>
		</item>
		<item>
		<title>$_SESSION and register globals in PHP</title>
		<link>http://www.twoscomplement.com/2008/01/08/_session-and-register-globals-in-php/</link>
		<comments>http://www.twoscomplement.com/2008/01/08/_session-and-register-globals-in-php/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 10:14:04 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[$_SESSION]]></category>

		<category><![CDATA[register globals]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2008/01/08/_session-and-register-globals-in-php/</guid>
		<description><![CDATA[I spent a silly amount of time getting to bottom of a bug in a php
script I was maintaining. The script was using the session to store a
list of service names, among other things:

$_SESSION["servicename"] = array("Just", "Some", "List", "Of", "Names");

But for some strange reason, this list of names was being reduced to
just the last item [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a silly amount of time getting to bottom of a bug in a php<br />
script I was maintaining. The script was using the session to store a<br />
list of service names, among other things:</p>
<pre>
$_SESSION["servicename"] = array("Just", "Some", "List", "Of", "Names");
</pre>
<p>But for some strange reason, this list of names was being reduced to<br />
just the last item in the list. Stranger still, this was only<br />
happening on the live server and not on my machine.</p>
<p>The reason turned out to be register globals. They were turned on<br />
(don&#8217;t do this - its a terrible security hole) for the server and not<br />
for my machine. When register globals are on, all the POST and GET<br />
parameters to the script are exposed as variables at the global scope.<br />
For example, hitting your script with a parameter such as</p>
<pre>"myscript.php?foo=bar"</pre>
<p>will assign the value &#8220;bar&#8221; to a global variable called $foo.</p>
<pre>print $foo; //prints the value "bar"</pre>
<p>What I hadn&#8217;t realised, however, was that the contents of $_SESSION<br />
are also exposed as variables in the same way. And, of course, I&#8217;d<br />
used a variable with the same name without thinking. And assigned to<br />
it, overwriting the data in $_SESSION:</p>
<pre>
$servicenames = $_SESSION["servicename"];

foreach($servicenames as $servicename) // &lt;-- problem!
{
    print "$servicename &lt;br /&gt;";
}
</pre>
<p>Hence I was left with the last item in the list. This is one of many<br />
reasons to write scripts which DON&#8217;T rely on register globals being<br />
turned on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2008/01/08/_session-and-register-globals-in-php/feed/</wfw:commentRss>
		</item>
		<item>
		<title>More fun with IE6</title>
		<link>http://www.twoscomplement.com/2007/11/19/more-fun-with-ie6/</link>
		<comments>http://www.twoscomplement.com/2007/11/19/more-fun-with-ie6/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 22:32:03 +0000</pubDate>
		<dc:creator>Fiona</dc:creator>
		
		<category><![CDATA[Browser Quirks]]></category>

		<category><![CDATA[GD]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2007/11/19/more-fun-with-ie6/</guid>
		<description><![CDATA[Marks last post reminded me of a little gotcha I came across with IE6.
Generally when using GD or any such image manipulation stuff server-side, you usually check the MIME type and do whatever is necessary with whatever file you&#8217;re given. image/gif, image/png etc&#8230;
IE6 is funny with JPGs that you upload though, most other browsers will [...]]]></description>
			<content:encoded><![CDATA[<p>Marks last post reminded me of a little gotcha I came across with IE6.</p>
<p>Generally when using GD or any such image manipulation stuff server-side, you usually check the MIME type and do whatever is necessary with whatever file you&#8217;re given. image/gif, image/png etc&#8230;</p>
<p>IE6 is funny with JPGs that you upload though, most other browsers will send the MIME type along with the file as image/jpeg. But IE6 sees <strong>image/pjpeg</strong>.</p>
<p>I&#8217;m assuming this is only the case for progressive JPEGs - though I haven&#8217;t properly done the research.<br />
This had me driving up the wall for a while, images wouldn&#8217;t upload properly, I assumed it was the HTML of course, turns out I just wasn&#8217;t detecting the file type as being a JPEG.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2007/11/19/more-fun-with-ie6/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Image Submit in IE 6</title>
		<link>http://www.twoscomplement.com/2007/11/19/image-submit-in-ie-6/</link>
		<comments>http://www.twoscomplement.com/2007/11/19/image-submit-in-ie-6/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 15:26:57 +0000</pubDate>
		<dc:creator>Mark</dc:creator>
		
		<category><![CDATA[Browser Quirks]]></category>

		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://blog.jankle.com/2007/11/19/image-submit-in-ie-6/</guid>
		<description><![CDATA[I&#8217;ve just run into a little gotcha with the &#8220;image&#8221; type input tag in HTML:

&#60;input type="image" src="foobar.gif" name="my_parameter" value="5" /&#62;

In Firefox, and probably every other browser other than Internet
Explorer, clicking this submit button will post to the next page 3
parameters:

&#8220;my_parameter&#8221;, with a value of &#8220;5&#8243;
&#8220;my_parameter.x&#8221; with the x coordinate of the mouse on the button
when [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just run into a little gotcha with the &#8220;image&#8221; type input tag in HTML:</p>
<pre>
&lt;input type="image" src="foobar.gif" name="my_parameter" value="5" /&gt;
</pre>
<p>In Firefox, and probably every other browser other than Internet<br />
Explorer, clicking this submit button will post to the next page 3<br />
parameters:</p>
<ul>
<li>&#8220;my_parameter&#8221;, with a value of &#8220;5&#8243;</li>
<li>&#8220;my_parameter.x&#8221; with the x coordinate of the mouse on the button<br />
when it was clicked</li>
<li>&#8220;my_parameter.y&#8221; with the y coordinate of the mouse</li>
</ul>
<p>The x and y coordinates are not important for what I was doing - the<br />
important part was that the action of clicking the button submitted a<br />
name-value pair. This meant I could have multiple image submit buttons<br />
at the end of a form and depending on which the user clicked, a<br />
different value would be posted to the next page along with the rest<br />
of the form data.</p>
<p>Internet Explorer 6 (and below, presumably), has other ideas. This<br />
browser submits the following:</p>
<ul>
<li>&#8220;my_parameter_x&#8221; - the x mouse coordinate</li>
<li>&#8220;my_parameter_y&#8221; - the y mouse coordinate</li>
</ul>
<p>Not only does it break the standard by using underscores but it fails<br />
to send the contents of the value attribute at all.</p>
<p>The solution? Probably to use the standard submit button:</p>
<pre>
&lt;input type="submit" name="my_parameter" value="5" &gt;
</pre>
<p>This will post the correct parameter, however the text shown on the<br />
button will be the contents of the value attribute: &#8220;5&#8243;. In my case<br />
this won&#8217;t be suitable - I shall have to come up with something else.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.twoscomplement.com/2007/11/19/image-submit-in-ie-6/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
