title: How do I get Nokogiri to understand my namespaces?
body: <p>I have the following XML document:</p>
  
  <pre><code>&lt;samlp:LogoutRequest ID="123456789" Version="2.0" IssueInstant="200904051217"&gt;
    &lt;saml:NameID&gt;@NOT_USED@&lt;/saml:NameID&gt;
    &lt;samlp:SessionIndex&gt;abcdefg&lt;/samlp:SessionIndex&gt;
  &lt;/samlp:LogoutRequest&gt;
  </code></pre>
  
  <p>I'd like to get the content of the <code>SessionIndex</code> (that is, 'abcdefg') out of it.  I've tried this:</p>
  
  <pre><code>XPATH_QUERY = "LogoutRequest[@ID][@Version='2.0'][IssueInstant]/SessionIndex"
  SAML_XMLNS  = 'urn:oasis:names:tc:SAML:2.0:assertion'
  SAMLP_XMLNS = 'urn:oasis:names:tc:SAML:2.0:protocol'
  
  require 'nokogiri'
  doc = Nokogiri::XML(xml)
  doc.xpath(XPATH_QUERY, 'saml' =&gt; SAML_XMLNS, 'samlp' =&gt; SAMLP_XMLNS)
  </code></pre>
  
  <p>but I get the following errors:</p>
  
  <pre><code>Nokogiri::XML::SyntaxError: Namespace prefix samlp on LogoutRequest is not defined
  Nokogiri::XML::SyntaxError: Namespace prefix saml on NameID is not defined
  Nokogiri::XML::SyntaxError: Namespace prefix samlp on SessionIndex is not defined
  </code></pre>
  
  <p>I've tried adding the namespaces to the XPath query, but that doesn't change anything.</p>
  
  <p>Why can't I convince Nokogiri that the namespaces are valid?</p>