<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.0.9">
</HEAD>
<BODY>
Hi<BR>
<BR>
I am having some problem using JDOM XPath class with Namespaces. The following JUnit test case code fails due to the value returned by 'selectSingleNode()' is always null:<BR>
<BR>
<TT> public static final String XML_DOI_BATCH_A_XMLNS_VAL = &quot;<A HREF="http://www.crossref.org/schema/2.0.5">http://www.crossref.org/schema/2.0.5</A>&quot;;<BR>
 public static final String XML_DOI_BATCH_A_XMLNS_XSI = &quot;xsi&quot;;<BR>
 public static final String XML_DOI_BATCH_A_XMLNS_XSI_VAL = &quot;<A HREF="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A>&quot;;<BR>
<BR>
        private void assertJournalTitle(String xmlDoc) throws Exception {<BR>
                StringReader inReader = new StringReader(xmlDoc);<BR>
                SAXBuilder saxBuilder = new SAXBuilder(false);<BR>
                Document doc = saxBuilder.build(inReader);<BR>
                <BR>
                assertNotNull(doc);<BR>
                <BR>
                XPath journalTitleXPath = XPath.newInstance(&quot;/doi_batch/body/journal/journal_metadata/full_title&quot;);<BR>
<BR>
                journalTitleXPath.addNamespace(Namespace.getNamespace(JournalConstants.XML_DOI_BATCH_A_XMLNS_VAL));<BR>
                journalTitleXPath.addNamespace(Namespace.getNamespace(<BR>
                        JournalConstants.XML_DOI_BATCH_A_XMLNS_XSI,<BR>
                        JournalConstants.XML_DOI_BATCH_A_XMLNS_XSI_VAL));<BR>
<BR>
                Element fullTitle = (Element) journalTitleXPath.selectSingleNode(doc);<BR>
&nbsp;&nbsp; <BR>
&nbsp;&nbsp; // the line below fails the assertion, i.e. fullTitle is null value<BR>
                assertNotNull(fullTitle);<BR>
                assertEquals(expectedJournalTitle, fullTitle.getText());<BR>
        }<BR>
</TT><BR>
<BR>
This is the XML I am trying to test (please note that this may fail if you turn ON the validation):<BR>
<BR>
<TT>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<BR>
&lt;doi_batch xmlns=&quot;http://www.crossref.org/schema/2.0.5&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; version=&quot;2.0.5&quot;&gt;<BR>
&nbsp; &lt;head&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;batch_id&gt;extenza66&lt;/batch_id&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;timestamp&gt;20031113164919&lt;/timestamp&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;doi_batch&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;name&gt;Extenza&lt;/name&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;email_address&gt;<A HREF="mailto:test1@bsg.co.uk">test1@bsg.co.uk</A>&lt;/email_address&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;/doi_batch&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;registrant&gt;Swets and Zeitlinger Publishers&lt;/registrant&gt;<BR>
&nbsp; &lt;/head&gt;<BR>
&nbsp; &lt;body&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;journal&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;journal_metadata language=&quot;en&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;full_title&gt;Aquatic Insects &amp;amp; some &amp;lt;xml&amp;gt;&lt;/full_title&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;abbrev_title&gt;Aquat insects&lt;/abbrev_title&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;issn media_type=&quot;electronic&quot;&gt;0165-0424&lt;/issn&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/journal_metadata&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;journal_issue&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;publication_date media_type=&quot;print&quot;&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;year&gt;2002&lt;/year&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/publication_date&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;journal_volume&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;volume&gt;23&lt;/volume&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/journal_volume&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;issue&gt;106&lt;/issue&gt;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/journal_issue&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;/journal&gt;<BR>
&nbsp; &lt;/body&gt;<BR>
&lt;/doi_batch&gt;<BR>
</TT><BR>
I am using JDOM 1.0-b9.<BR>
<BR>
Could someone please help me figure out why the node in question is never selected?<BR>
<BR>
Best regards,<BR>
<BR>
Ben<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
<PRE>-- 
benjamin kopic
m: +44 (0)780 154 7643
t: +44 (0)20 7794 3090
e: benjamin.kopic@panContext.com
w: http://www.panContext.com/</PRE>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>