<?xml version="1.0" encoding="utf-8"?><?xml-stylesheet type='text/xsl' href='http://wkfry.spaces.live.com/mmm2008-07-24_12.50/rsspretty.aspx?rssquery=en-US;http%3a%2f%2fwkfry.spaces.live.com%2fcategory%2fXML%2ffeed.rss' version='1.0'?><rss version="2.0" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:msn="http://schemas.microsoft.com/msn/spaces/2005/rss" xmlns:live="http://schemas.microsoft.com/live/spaces/2006/rss" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Bill's Space: XML</title><description /><link>http://wkfry.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&amp;_c=BlogPart&amp;partqs=catXML</link><language>en-US</language><pubDate>Tue, 20 May 2008 16:21:24 GMT</pubDate><lastBuildDate>Tue, 20 May 2008 16:21:24 GMT</lastBuildDate><generator>Microsoft Spaces v1.1</generator><docs>http://www.rssboard.org/rss-specification</docs><ttl>60</ttl><cf:parentRSS>http://wkfry.spaces.live.com/blog/feed.rss</cf:parentRSS><live:type>blogcategory</live:type><live:identity><live:id>-4671077372406318224</live:id><live:alias>wkfry</live:alias></live:identity><cf:listinfo><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="typelabel" label="Type" /><cf:group ns="http://schemas.microsoft.com/live/spaces/2006/rss" element="tag" label="Tag" /><cf:group element="category" label="Category" /><cf:sort element="pubDate" label="Date" data-type="date" default="true" /><cf:sort element="title" label="Title" data-type="string" /><cf:sort ns="http://purl.org/rss/1.0/modules/slash/" element="comments" label="Comments" data-type="number" /></cf:listinfo><item><title>Default Namespaces and XML: Who Knew!?!?</title><link>http://wkfry.spaces.live.com/Blog/cns!BF2CFFE0D35B3B70!231.entry</link><description>&lt;p&gt;I work a lot with XML and XML will obviously play an important role in future development. Over the last couple of months, I've been observing some incredibly strange behaviors with namespaces. I was certain that I must be observing a bug in Microsoft's XML Parsers, so today I decided I was going to finally figure out what was happening. &lt;p&gt;Take the following example:&lt;pre&gt;&lt;code&gt;&amp;lt;html xmlns=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;&lt;span style="color:blue;font-family:courier new;text-decoration:underline"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;/a&gt;&amp;quot;&amp;gt; 
    …     
    &amp;lt;a href=&amp;quot;http:someurl&amp;quot; mce_href=&amp;quot;http:someurl&amp;quot; &amp;gt;     
    … 
&amp;lt;/html&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Question #1:&lt;/strong&gt; What is that namespace for the &amp;quot;a&amp;quot; element?
&lt;p&gt;&lt;strong&gt;Answer #1:&lt;/strong&gt; It's &lt;em&gt;&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&amp;quot;&lt;/em&gt;.
&lt;p&gt;&lt;strong&gt;Question #2:&lt;/strong&gt; What is the namespace for the &amp;quot;href&amp;quot; attribute?
&lt;p&gt;&lt;strong&gt;Answer #2:&lt;/strong&gt; Did you say &lt;em&gt;&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&amp;quot;&lt;/em&gt;? &lt;span style="color:red"&gt;Wrong! It's actually &lt;em&gt;null&lt;/em&gt;!&lt;/span&gt;
&lt;p&gt;What? That didn't make any sense, so then I tried using an explicit prefix on the elements…&lt;pre&gt;&lt;code&gt;&amp;lt;h:html xmlns:h=&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;&lt;span style="color:blue;font-family:courier new;text-decoration:underline"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;/a&gt;&amp;quot;&amp;gt; 
     … 
     &amp;lt;h:a href=&amp;quot;http:someurl&amp;quot; mce_href=&amp;quot;http:someurl&amp;quot; &amp;gt; 
     … 
&amp;lt;/h:html&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When you use an explicit prefix on elements then the namespace for both &amp;quot;a&amp;quot; and &amp;quot;href&amp;quot; becomes &lt;em&gt;&amp;quot;&lt;a href="http://www.w3.org/1999/xhtml"&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&amp;quot;&lt;/em&gt;.
&lt;p&gt;This certainly seemed like a bug, so I went straight to the source. . . the W3C.
&lt;p&gt;&lt;a href="http://www.w3.org/TR/2006/REC-xml-names-20060816/"&gt;http://www.w3.org/TR/2006/REC-xml-names-20060816/#scoping&lt;/a&gt;
&lt;p&gt;Amazingly enough, it's not a bug! If you use a default namespace, then elements with no prefix belong to the default namespace; however, attributes have a null namespace. If you use a namespace prefix on elements, then attributes with no prefix have the same namespace as their containing element!
&lt;p&gt;I have absolutely no idea why the W3C chose this behavior, but it's incredibly important if you are trying to write XPath expressions or are using the Microsoft XML classes.
&lt;p style="text-align:center"&gt;&lt;span style="color:red"&gt;Understanding this behavior should save you from a lot of frustration! &lt;/span&gt;
&lt;p&gt;Happy Coding!&lt;img src="http://c.services.spaces.live.com/CollectionWebService/c.gif?cid=-4671077372406318224&amp;page=RSS%3a+Default+Namespaces+and+XML%3a+Who+Knew!%3f!%3f&amp;referrer=" width="1px" height="1px" border="0" alt=""&gt;&lt;img style="position:absolute" alt="" width="0px" height="0px" src="http://c.live.com/c.gif?NC=31263&amp;amp;NA=1149&amp;amp;PI=73329&amp;amp;RF=&amp;amp;DI=3919&amp;amp;PS=85545&amp;amp;TP=wkfry.spaces.live.com&amp;amp;GT1=wkfry"&gt;</description><comments>http://wkfry.spaces.live.com/Blog/cns!BF2CFFE0D35B3B70!231.entry#comment</comments><guid isPermaLink="true">http://wkfry.spaces.live.com/Blog/cns!BF2CFFE0D35B3B70!231.entry</guid><pubDate>Sat, 28 Apr 2007 20:08:38 GMT</pubDate><slash:comments>0</slash:comments><msn:type>blogentry</msn:type><live:type>blogentry</live:type><live:typelabel>Blog entry</live:typelabel><wfw:commentRss>http://wkfry.spaces.live.com/blog/cns!BF2CFFE0D35B3B70!231/comments/feed.rss</wfw:commentRss><wfw:comment>http://wkfry.spaces.live.com/Blog/cns!BF2CFFE0D35B3B70!231.entry#comment</wfw:comment><dcterms:modified>2007-07-29T20:24:27Z</dcterms:modified></item></channel></rss>