<!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 Laurent,<BR>
<BR>
Thank you for the reply it worked perfectly. Do you think it might be worthwhile adding additional comment to <B>addNamespace()</B> method telling the user to create a dummy prefix if an empty prefix is defined with a Namespace? It wasn't clear to me from the JavaDoc that I could use a dummy namespace prefix.<BR>
<BR>
Best regards<BR>
<BR>
Ben<BR>
<BR>
<BR>
On Thu, 2003-11-13 at 17:51, Laurent Bihanic wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373"><I>Hi,
There is no default namespace in XPath. Hence, all namespaces must have a
prefix in the XPath expressions. The prefix does not have to match the one in
the document.
XPath journalTitleXPath =
XPath.newInstance("/foo:doi_batch/foo:body/foo:journal/foo:journal_metadata/foo:full_title");
journalTitleXPath.addNamespace(Namespace.getNamespace("foo",
JournalConstants.XML_DOI_BATCH_A_XMLNS_VAL));
should work.
Laurent
Benjamin Kopic wrote:
> 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:
>
> XPath journalTitleXPath =
> XPath.newInstance("/doi_batch/body/journal/journal_metadata/full_title");
>
> journalTitleXPath.addNamespace(Namespace.getNamespace(JournalConstants.XML_DOI_BATCH_A_XMLNS_VAL));
> journalTitleXPath.addNamespace(Namespace.getNamespace(
> JournalConstants.XML_DOI_BATCH_A_XMLNS_XSI,
> JournalConstants.XML_DOI_BATCH_A_XMLNS_XSI_VAL));
>
> Element fullTitle = (Element) journalTitleXPath.selectSingleNode(doc);
>
> // the line below fails the assertion, i.e. fullTitle is null value
> assertNotNull(fullTitle);
> assertEquals(expectedJournalTitle, fullTitle.getText());
> }
_______________________________________________
To control your jdom-interest membership:</FONT>
<A HREF="http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com"><U>http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com</U></I></A></PRE>
</BLOCKQUOTE>
<PRE><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>
</PRE>
</BODY>
</HTML>