<!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>
You really need knowlege in your application as to the namespace URIs - I take the point that you have URIs that are changing, but it is the URI and <B>not</B> the prefix that is important in XML, indeed the prefix is essentially irrelevant. Prefixes are purely for brevity and convenience in XML syntax. The actual prefix used can be changed by the user without impacting the underlying result. It is very, very bad practice to assume specific prefixes (this goes totally against the XML ethos).<BR>
<BR>
You can do something like:<BR>
<BR>
private static final Properties URIS = new Properties();<BR>
<BR>
static {<BR>
&nbsp;&nbsp;&nbsp; URIS.load(getClass().getResourceAsStream(&quot;uris.properties&quot;));<BR>
}<BR>
<BR>
private static final String MODS_URI = <A HREF="http://www.loc.dov/mods/v3">URIS.</A>getProperty(&quot;mods&quot;);<BR>
private static final String MIX_URI = URIS.getProperty(&quot;mix&quot;);<BR>
<BR>
private static final Namespace MODS = Namespace.getNamespace(&quot;totallyArbitraryPrefixDoesNotHaveToMatchTheDocumentButIsUniqueInThisDocumentsSetOfPrefixes&quot;, MODS_URI);<BR>
private static final Namespace MIX = Namespace.getNamespace(&quot;anotherTotallyArbitraryPrefixDoesNotHaveToMatchTheDocumentButIsUniqueInThisDocumentsSetOfPrefixes&quot;, MIX_URI);<BR>
<BR>
...<BR>
<BR>
and to access the required attribute in the MODS namespace from the required element in the MIX namespace:<BR>
<BR>
doc.getRootElement().getChild(&quot;a&quot;, MIX).getAttribute(&quot;x&quot;, MODS);<BR>
<BR>
Better still, instead of using the JDOM API directly, use an XPath of the form &quot;prefixmix:a/@prefixmods:x&quot; initialized using the two required namespaces (clearly using nice, short XPath-scope unique prefixes), executed against the root element.<BR>
<BR>
Hope that's helpful!<BR>
<BR>
Phil :n)<BR>
<BR>
PS: You would put the file &quot;uris.properties&quot; in the class's package and populate it like:<BR>
<BR>
# Define the URIs used in the code. The key is not the prefix<BR>
# used in the XML document or document accessing code<BR>
# but is just a meaningful key for accessing the URI definitions<BR>
mods=<A HREF="http://www.loc.gov/mods/v3">http://www.loc.gov/mods/v3</A><BR>
mix=<A HREF="http://www.loc.gov/mix/">http://www.loc.gov/mix/</A><BR>
<BR>
On Thu, 2004-02-05 at 08:58, Fr&#233;d&#233;ric Laurent wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE><FONT COLOR="#737373"><I>Quoting Garey Mills &lt;gmills@library.berkeley.edu&gt;:
&gt; Hi - 

Hello


&gt; 
&gt;         I am using JDOM to parse documents that use attributes in a number
&gt; of different namespaces. The namespaces correspond to standards that are
&gt; being revised, so I can't be sure what their URI is (since each revision
&gt; is given a new URI).
&gt; 
&gt;         The namespaces are declared in the root element, for example:
&gt; 
&gt; xmlns:mets=&quot;</FONT><A HREF="http://www.loc.gov/METS/"><U>http://www.loc.gov/METS/&quot;</U></A>
<FONT COLOR="#737373">&gt; xmlns:moa2=&quot;</FONT><A HREF="http://sunsite.berkeley.edu/MOA2/"><U>http://sunsite.berkeley.edu/MOA2/&quot;</U></A>
<FONT COLOR="#737373">&gt; xmlns:mods=&quot;</FONT><A HREF="http://www.loc.gov/mods/v3"><U>http://www.loc.gov/mods/v3&quot;</U></A>
<FONT COLOR="#737373">&gt; xmlns:mix=&quot;</FONT><A HREF="http://www.loc.gov/mix/"><U>http://www.loc.gov/mix/&quot;</U></A>
<FONT COLOR="#737373">&gt; xmlns:xlink=&quot;</FONT><A HREF="http://www.w3.org/TR/xlink"><U>http://www.w3.org/TR/xlink&quot;</U></A>
<FONT COLOR="#737373">&gt; xmlns:xsi=&quot;</FONT><A HREF="http://www.w3.org/2001/XMLSchema-instance"><U>http://www.w3.org/2001/XMLSchema-instance&quot;</U></A>
<FONT COLOR="#737373">&gt; 
&gt; 
&gt;         If, at some point in the document, I want to retrieve an attribute
&gt; that belongs to, say, the 'mods' namespace, can I just use the prefix?
&gt; 
&gt; 
&gt;         Attribute x = myElement.getAttribute(&quot;x&quot;, &quot;mods&quot;);
&gt; 
&gt;         I don't think I can because getAttribute needs a Namespace and not
&gt; a string
&gt; 
&gt;         So do I have to do something more convoluted, such as retrieve the
&gt; namespaces defined on the element, search for the one with the name &quot;mods&quot;
&gt; and then include that one in the get Attribute call?
&gt; 
&gt;         Or is there someway I can access the namespaces declared in the
&gt; root element?

for sure !
see </FONT>
<A HREF="http://www.jdom.org/docs/apidocs/org/jdom/Element.html#getNamespace("><U>http://www.jdom.org/docs/apidocs/org/jdom/Element.html#getNamespace(</U></A><FONT COLOR="#737373">)
and </FONT><A HREF="http://www.jdom.org/docs/apidocs/org/jdom/Element.html#getAdditionalNamespaces("><U>http://www.jdom.org/docs/apidocs/org/jdom/Element.html#getAdditionalNamespaces(</U></A><FONT COLOR="#737373">)

&gt;         In other words, what does it get me that namespaces are declared
&gt; in the root element?

here is an sample that might give you some clue
Retrieve all the namespaces defined on the root element 
and choose which object (Namespace objet) defines your prefix
or you URI... Then use this namespace objet as getElement or
getAttribute paramter...

It's written in jython (to be shorter and faster)


------------------------------------------------------------
from java.io import *
from java.lang import *
from org.jdom.input import *
from org.jdom.xpath import *

xmlbuffer =&quot;&quot;&quot;&lt;?xml version='1.0' encoding='ISO-8859-1'?&gt;
&lt;rootElt xmlns:mets=&quot;</FONT><A HREF="http://www.loc.gov/METS/"><U>http://www.loc.gov/METS/&quot;</U></A>
<FONT COLOR="#737373">        xmlns:moa2=&quot;</FONT><A HREF="http://sunsite.berkeley.edu/MOA2/"><U>http://sunsite.berkeley.edu/MOA2/&quot;</U></A>
<FONT COLOR="#737373">        xmlns:mods=&quot;</FONT><A HREF="http://www.loc.gov/mods/v3"><U>http://www.loc.gov/mods/v3&quot;</U></A>
<FONT COLOR="#737373">        xmlns:mix=&quot;</FONT><A HREF="http://www.loc.gov/mix/"><U>http://www.loc.gov/mix/&quot;</U></A>
<FONT COLOR="#737373">        xmlns:xlink=&quot;</FONT><A HREF="http://www.w3.org/TR/xlink"><U>http://www.w3.org/TR/xlink&quot;</U></A>
<FONT COLOR="#737373">        xmlns:xsi=&quot;</FONT><A HREF="http://www.w3.org/2001/XMLSchema-instance"><U>http://www.w3.org/2001/XMLSchema-instance&quot;</U></A>
<FONT COLOR="#737373">&gt;
&lt;mix:a mods:attr=&quot;test&quot;/&gt;
&lt;/rootElt&gt;
&quot;&quot;&quot;

docBuilder = SAXBuilder()
doc = SAXBuilder().build(StringReader(xmlbuffer))
Result = StringBuffer()

nsList = doc.getRootElement().getAdditionalNamespaces()
mixNS = modsNS = None
for ns in nsList:
        if ns.getURI() == &quot;</FONT><A HREF="http://www.loc.gov/mix/"><U>http://www.loc.gov/mix/&quot;:</U></A>
<FONT COLOR="#737373">                mixNS = ns
        elif ns.getURI() == &quot;</FONT><A HREF="http://www.loc.gov/mods/v3"><U>http://www.loc.gov/mods/v3&quot;:</U></A>
<FONT COLOR="#737373">                modsNS = ns


EltA = doc.getRootElement().getChild(&quot;a&quot;,mixNS)
print &quot;Elt A : &quot;,EltA
attr = EltA.getAttribute(&quot;attr&quot;,modsNS)
print &quot;Attr  name (&quot;,attr.getName(),&quot;) value  (&quot;,attr.getValue(),&quot;)&quot;
print &quot;Attr dump : &quot;,attr

------------------------------------------------------------

output is 

     [java] Elt A :  [Element: &lt;mix:a [Namespace: </FONT><A HREF="http://www.loc.gov/mix/]/"><U>http://www.loc.gov/mix/]/</U></A><FONT COLOR="#737373">&gt;]
     [java] Attr  name ( attr ) value  ( test )
     [java] Attr dump :  [Attribute: mods:attr=&quot;test&quot;]


HTH 
cheers</I></FONT></PRE>
</BLOCKQUOTE>
<PRE><TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
-- <BR>
Phil Weighill-Smith &lt;<A HREF="mailto:phil.weighill-smith@volantis.com"><U>phil.weighill-smith@volantis.com</U></A>&gt;<BR>
Volantis Systems
</TD>
</TR>
</TABLE>
</PRE>
</BODY>
</HTML>