[jdom-interest] How do I use namespaces?

Garey Mills gmills at library.berkeley.edu
Wed Feb 4 15:49:44 PST 2004


Hi - 

	I am using JDOM to parse documents that use attributes in a number
of different namespaces. The namespaces correspond to standards that are
being revised, so I can't be sure what their URI is (since each revision
is given a new URI).

	The namespaces are declared in the root element, for example:

xmlns:mets="http://www.loc.gov/METS/"
xmlns:moa2="http://sunsite.berkeley.edu/MOA2/"
xmlns:mods="http://www.loc.gov/mods/v3" 
xmlns:mix="http://www.loc.gov/mix/"
xmlns:xlink="http://www.w3.org/TR/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


	If, at some point in the document, I want to retrieve an attribute
that belongs to, say, the 'mods' namespace, can I just use the prefix?


	Attribute x = myElement.getAttribute("x", "mods");

	I don't think I can because getAttribute needs a Namespace and not
a string

	So do I have to do something more convoluted, such as retrieve the
namespaces defined on the element, search for the one with the name "mods"
and then include that one in the get Attribute call?

	Or is there someway I can access the namespaces declared in the
root element?

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

Thanks;

Garey Mills
Library Systems Office
UC Berkeley





More information about the jdom-interest mailing list