<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:admin="http://webns.net/mvcb/"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
	<channel> 

      <title>Comments on: Only Fools and Webgeeks</title>
      <link>http://ask.metafilter.com/63732/Only-Fools-and-Webgeeks/</link>
      <description>Comments on Ask MetaFilter post Only Fools and Webgeeks</description>
	  	  <pubDate>Wed, 30 May 2007 17:11:06 -0800</pubDate>
      <lastBuildDate>Wed, 30 May 2007 17:11:06 -0800</lastBuildDate>
      <language>en-us</language>
	  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
	  <ttl>60</ttl>

<item>
  	<title>Question: Only Fools and Webgeeks</title>
  	<link>http://ask.metafilter.com/63732/Only-Fools-and-Webgeeks</link>	
  	<description>I need to parse an XML flat file with JavaScript, and I&apos;m struggling with how to use the DOM to select one particular node via an attribute then use its child nodes to populate some values. [more] &lt;br /&gt;&lt;br /&gt; (Let&apos;s get one thing out of the way first: I don&apos;t think I can use XSLT. Please prove me wrong, but the problem is that I&apos;m taking the XML node values and using them in a JavaScript function (that calls runs embedded Flash videos), and by rule don&apos;t I have to enclose JavaScript within an XSLT stylesheet inside CDATA, thus meaning any XSLT tag inside won&apos;t be parsed?)&lt;br&gt;
&lt;br&gt;
(Oh, and my DBA is so overwhelmed there&apos;s no way I can get his attention to give me some tables before July... and I need this done a week ago.)&lt;br&gt;
&lt;br&gt;
Anyway, here&apos;s the basic XML, really simplified:&lt;br&gt;
&amp;lt;root&amp;gt;&lt;br&gt;
&amp;lt;president ident=&quot;Clinton_Bill&quot; /&amp;gt;&lt;br&gt;
&amp;lt;name&amp;gt; William J. Clinton &amp;lt;/name&amp;gt;&lt;br&gt;
&amp;lt;video url=&quot;http://someurl.com/clinton.flv&quot; /&amp;gt;&lt;br&gt;
&amp;lt;/root&amp;gt;&lt;br&gt;
&lt;br&gt;
What I want is to have a query string on the URI, then use the value of that query string to match it against the ident attribute on president and if it matches use that node&apos;s values on the page.&lt;br&gt;
&lt;br&gt;
In XSLT, I would set a param we&apos;ll call &quot;query&quot; and give it a value of the query string, then select root/president[@ident = $query]. &lt;br&gt;
&lt;br&gt;
So, how do I do this bit in JavaScript? I know how to load the node through XMLHTTPRequest and other methods, but how do I traverse the node until I find the right one? I&apos;m thinking I run a for-next loop and if the attribute value matches process it, but that seems... inefficient. Is that the only way? Is there a better way?&lt;br&gt;
&lt;br&gt;
I&apos;ve gone through a dozen pages, but I haven&apos;t found anyone attempting to do this, which seems really strange to me. And, admittedly, JavaScript is my weakest web language, so there&apos;s that going against me.</description>
  	<guid isPermaLink="false">post:ask.metafilter.com,2008:site.63732</guid>
  	<pubDate>Wed, 30 May 2007 16:49:58 -0800</pubDate>
  	<dc:creator>dw</dc:creator>
	
	<category>JavaScript</category>
	
	<category>XML</category>
	
	<category>XSLT</category>
	
	<category>DOM</category>
	
</item>
<item>
  	<title>By: Khalad</title>
  	<link>http://ask.metafilter.com/63732/Only-Fools-and-Webgeeks#958826</link>	
  	<description>Yep, just loop through. Really, evaluating an XPath expression does a whole lot more than just a simple for loop, so you oughtn&apos;t worry about efficiency just yet.&lt;br&gt;
&lt;br&gt;
Depending on the assumptions you can make about the structure of the XML, you can also be smarter. Like use document.getElementsByTagName (if you&apos;re not using XML namespacing) to find all the &amp;lt;president/&amp;gt;s.&lt;br&gt;
&lt;br&gt;
Alternatively, the major web browsers support a subset of XPath via selectNodes() and selectSingleNode().</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.63732-958826</guid>
  	<pubDate>Wed, 30 May 2007 17:11:06 -0800</pubDate>
  	<dc:creator>Khalad</dc:creator>
</item>
<item>
  	<title>By: Civil_Disobedient</title>
  	<link>http://ask.metafilter.com/63732/Only-Fools-and-Webgeeks#958898</link>	
  	<description>&lt;a href=&quot;http://developer.mozilla.org/en/docs/Introduction_to_using_XPath_in_JavaScript#Evaluating_against_an_XML_document_within_an_Extension&quot;&gt;xpath&lt;/a&gt;?</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.63732-958898</guid>
  	<pubDate>Wed, 30 May 2007 18:39:09 -0800</pubDate>
  	<dc:creator>Civil_Disobedient</dc:creator>
</item>
<item>
  	<title>By: dw</title>
  	<link>http://ask.metafilter.com/63732/Only-Fools-and-Webgeeks#959130</link>	
  	<description>Huh. Someone told me that there was no xpath support. Quite wrongly, it would seem.&lt;br&gt;
&lt;br&gt;
Apparently, selectNodes with XPath is only MSXML; Mozilla implements XPath &amp;quot;more completely&amp;quot; which requires some testing and hacking. But it looks like there&apos;s boilerplate out there for that.</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.63732-959130</guid>
  	<pubDate>Wed, 30 May 2007 23:20:57 -0800</pubDate>
  	<dc:creator>dw</dc:creator>
</item>
<item>
  	<title>By: fletchmuy</title>
  	<link>http://ask.metafilter.com/63732/Only-Fools-and-Webgeeks#960730</link>	
  	<description>If you&apos;re in control of the data format, and don&apos;t have to use XML, you might want to look into using &lt;a href=&quot;http://www.json.org/js.html&quot;&gt;JSON&lt;/a&gt; for your data.  In my experience, JSON is easier to get your head around than trying to parse XML.  You could even continue to use XML, but &lt;a href=&quot;http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html&quot;&gt;convert it to JSON&lt;/a&gt; to parse. &lt;br&gt;
&lt;br&gt;
Just an idea.  Good luck!</description>
  	<guid isPermaLink="false">comment:ask.metafilter.com,2008:site.63732-960730</guid>
  	<pubDate>Fri, 01 Jun 2007 08:30:30 -0800</pubDate>
  	<dc:creator>fletchmuy</dc:creator>
</item>

    </channel>
</rss>
