<?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>Web 3.0, 6 Bladed Razors, 7 Minute Abs &#187; XHTML</title>
	<atom:link href="http://www.zachleat.com/web/tag/xhtml/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zachleat.com/web</link>
	<description></description>
	<lastBuildDate>Fri, 09 Dec 2011 21:53:07 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Namespaces in Ext DomQuery</title>
		<link>http://www.zachleat.com/web/namespaces-in-ext-domquery/</link>
		<comments>http://www.zachleat.com/web/namespaces-in-ext-domquery/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 21:37:18 +0000</pubDate>
		<dc:creator>Zach Leatherman</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ExtJS]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[XML Namespaces]]></category>

		<guid isPermaLink="false">http://www.zachleat.com/web/2007/03/06/namespaces-in-ext-domquery/</guid>
		<description><![CDATA[Do you want to use custom attributes in your XHTML? Do you use the YUI Library and Jack Slocum&#8217;s wonderful DomQuery selector engine? If you want to select attribute nodes with a namespace in your XHTML, DomQuery does not support namespaces as an option to do so. But by adding a small snippet of code [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to use <a href="http://unspace.ca/discover/attributes/">custom attributes</a> in your XHTML?  Do you use the YUI Library and Jack Slocum&#8217;s wonderful <a href="http://www.jackslocum.com/blog/2007/01/11/domquery-css-selector-basic-xpath-implementation-with-benchmarks/">DomQuery selector engine</a>?</p>
<p>If you want to select attribute nodes with a namespace in your XHTML, DomQuery does not support namespaces as an option to do so.  But by adding a small snippet of code to DomQuery, we can make it do so.</p>
<p>As a standalone snippet executed after DomQuery is loaded.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">DomQuery</span>.<span style="color: #660066;">matchers</span>.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span>
	re<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/^(?:([\[\{])(?:@)?([\w-]+(?:\:[\w-]+))\s?(?:(=|.=)\s?['&quot;]?(.*?)[&quot;']?)?[\]\}])/</span><span style="color: #339933;">,</span>
	select<span style="color: #339933;">:</span> <span style="color: #3366CC;">'n = byAttribute(n, &quot;{2}&quot;, &quot;{4}&quot;, &quot;{3}&quot;, &quot;{1}&quot;);'</span>
<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>OR</strong> by adding an array entry into the DomQuery code matchers array (paste <em>after</em> line 479 of the <a href="http://www.yui-ext.com/deploy/yui-ext.0.40-alpha/source/DomQuery.js">17 January 2007 2:26:32 PM version</a>)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>
	re<span style="color: #339933;">:</span> <span style="color: #009966; font-style: italic;">/^(?:([\[\{])(?:@)?([\w-]+(?:\:[\w-]+))\s?(?:(=|.=)\s?['&quot;]?(.*?)[&quot;']?)?[\]\}])/</span><span style="color: #339933;">,</span>
	select<span style="color: #339933;">:</span> <span style="color: #3366CC;">'n = byAttribute(n, &quot;{2}&quot;, &quot;{4}&quot;, &quot;{3}&quot;, &quot;{1}&quot;);'</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I did not modify the existing matcher for attribute selection because I didn&#8217;t want to modify the speed of the existing code for non-namespaced attributes.  So by appending another entry to the end of the array, it&#8217;ll be used as a last resort if the other entries aren&#8217;t matched.</p>
<p>This approach relies on the assumption that when selecting an attribute with getAttribute, the browser interprets any namespace automatically: getAttribute(&#8216;myNamespace:myAttributeName&#8217;), as documented by the <a href="http://blogger.xs4all.nl/peterned/archive/2005/12/11/70033.aspx">peterned weblog</a>.  This was tested in Firefox 2 and IE 6.</p>
<p><strong>Usage:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#test-data span[myNameSpace:myAttribute=myValue]'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>on the following DOM</p>

<div class="wp_syntax"><div class="code"><pre class="xhtml" style="font-family:monospace;">&lt;div id=&quot;test-data&quot;&gt;
&lt;span myNameSpace:myAttribute=&quot;myValue&quot;&gt;&lt;/span&gt;
&lt;/div&gt;</pre></div></div>

<p>Other notes regarding DomQuery:</p>
<p>To select a node with a non-empty attribute value:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Ext.<span style="color: #660066;">query</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'#test-data span[myNameSpace:myAttribute]'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.zachleat.com/web/namespaces-in-ext-domquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

