[jdom-interest] Re: Very basic question about namespaces.

Elliotte Rusty Harold elharo at metalab.unc.edu
Wed Apr 17 03:40:44 PDT 2002


At 11:37 AM +0100 4/17/02, Bart Read wrote:
>Hi All,
>
>
>Just a quick query about namespaces.  Can't seem to find what I'm looking
>for in any of my books or on the web but somebody here is bound to know.
>
>We're using JDOM b8 in a messaging application that is used to transfer data
>between various organisations.  I have an element like this:
>
><spoxml:entity name="aaa">
>      <spoxml:parameter>
>       <spoxml:name>bbb</spoxml:name>
>       <spoxml:value>ccc</spoxml:value>
>      </spoxml:parameter>
>     ...
>     ...
></spoxml:entity>
>
>I want to extract the value of the 'name' attribute from the 'spoxml:entity'
>element, so do I use
>
>public java.lang.String getAttributeValue(java.lang.String name)
>
>or
>
>public java.lang.String getAttributeValue(java.lang.String name,
>                                           Namespace ns)
>
>to do it?
>

THe former.

>Is the attribute included within the 'spoxml' namespace because its parent
>element is within this namespace, or is it in the default namespace (i.e.
>would I need to call it 'spoxml:name' for it to be in the 'spoxml'
>namespace)?
>

Unprefixed attributes are never in any namespace. This is a 
fundamental rule of namespaces in XML.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|             http://www.cafeconleche.org/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+



More information about the jdom-interest mailing list