<!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 = "<A HREF="http://www.crossref.org/schema/2.0.5">http://www.crossref.org/schema/2.0.5</A>";<BR>
public static final String XML_DOI_BATCH_A_XMLNS_XSI = "xsi";<BR>
public static final String XML_DOI_BATCH_A_XMLNS_XSI_VAL = "<A HREF="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</A>";<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("/doi_batch/body/journal/journal_metadata/full_title");<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>
<BR>
// 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><?xml version="1.0" encoding="UTF-8"?><BR>
<doi_batch xmlns="http://www.crossref.org/schema/2.0.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0.5"><BR>
<head><BR>
<batch_id>extenza66</batch_id><BR>
<timestamp>20031113164919</timestamp><BR>
<doi_batch><BR>
<name>Extenza</name><BR>
<email_address><A HREF="mailto:test1@bsg.co.uk">test1@bsg.co.uk</A></email_address><BR>
</doi_batch><BR>
<registrant>Swets and Zeitlinger Publishers</registrant><BR>
</head><BR>
<body><BR>
<journal><BR>
<journal_metadata language="en"><BR>
<full_title>Aquatic Insects &amp; some &lt;xml&gt;</full_title><BR>
<abbrev_title>Aquat insects</abbrev_title><BR>
<issn media_type="electronic">0165-0424</issn><BR>
</journal_metadata><BR>
<journal_issue><BR>
<publication_date media_type="print"><BR>
<year>2002</year><BR>
</publication_date><BR>
<journal_volume><BR>
<volume>23</volume><BR>
</journal_volume><BR>
<issue>106</issue><BR>
</journal_issue><BR>
</journal><BR>
</body><BR>
</doi_batch><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>