You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Brenda Bell <bb...@juicesoftware.com> on 2002/07/12 21:46:41 UTC

Problem with attribute namespaces

I've used several different SAXParsers to parse the following document:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <businessList generic="1.0" operator="Microsoft Corporation"
truncated="false" xmlns="urn:uddi-org:api">
      <businessInfos>
        <businessInfo businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
          <name>XMethods</name>
          <description xml:lang="en">Web services resource
site</description>
          <serviceInfos>
            <serviceInfo serviceKey="d5b180a0-4342-11d5-bd6c-002035229c64"
businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
              <name>XMethods Barnes and Noble Quote</name>
            </serviceInfo>
            <serviceInfo serviceKey="ed85f000-4345-11d5-bd6c-002035229c64"
businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
              <name>XMethods Pacific Bell SMS Service</name>
            </serviceInfo>
            <serviceInfo serviceKey="d5921160-3e16-11d5-98bf-002035229c64"
businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
              <name>XMethods Delayed Stock Quotes</name>
            </serviceInfo>
            <serviceInfo serviceKey="618167a0-3e64-11d5-98bf-002035229c64"
businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
              <name>XMethods Currency Exchange Rates</name>
            </serviceInfo>
          </serviceInfos>
        </businessInfo>
      </businessInfos>
    </businessList>
  </soap:Body>
</soap:Envelope>

Where I'm having a problem is in my handler's startElement implementation.
Seems that attributes(idx).getURI() always returns an empty string.  For an
attribute like businessKey, I would have expected the default URI
"urn:uddi-org:api".

Is this a bug in the parser?  Or am I doing something wrong?

Re: Problem with attribute namespaces

Posted by Andy Clark <an...@apache.org>.
Brenda Bell wrote:
> Where I'm having a problem is in my handler's startElement 
> implementation.  Seems that attributes(idx).getURI() always returns an 
> empty string.  For an attribute like businessKey, I would have expected 
> the default URI "urn:uddi-org:api".
> 
> Is this a bug in the parser?  Or am I doing something wrong?

This is a common misunderstanding about namespaces and
attributes in XML. Unless attributes are prefixed, they
are NOT in ANY namespace. For example:

   <a:root xmlns:a='NSa' attr1='value1' a:attr2='value2'/>

The "attr1" attribute is not in any namespace whereas the
"attr2" attribute is in the "NSa" namespace.

Therefore, what you are seeing is not a bug in any of
the parsers that you are using (unless, of course, that
the parsers *are* returning namespace information for
unprefixed attributes). Namespaces in XML is just
defined to be this way.

-- 
Andy Clark * andyc@apache.org


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: Problem with attribute namespaces

Posted by Elliotte Rusty Harold <el...@metalab.unc.edu>.
At 3:46 PM -0400 7/12/02, Brenda Bell wrote:
I've used several different SAXParsers to parse the following document:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope 
xmlns:soap="<http://schemas.xmlsoap.org/soap/envelope/>http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>http://www.w3.org/2001/XMLSchema-instance" 
xmlns:xsd="<http://www.w3.org/2001/XMLSchema>http://www.w3.org/2001/XMLSchema">

   <soap:Body>
     <businessList generic="1.0" operator="Microsoft Corporation" 
truncated="false" xmlns="urn:uddi-org:api">
       <businessInfos>
         <businessInfo businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">



Where I'm having a problem is in my handler's startElement 
implementation.  Seems that attributes(idx).getURI() always returns 
an empty string.  For an attribute like businessKey, I would have 
expected the default URI "urn:uddi-org:api".

Is this a bug in the parser?  Or am I doing something wrong?

The latter. Default namespaces never apply to attributes. The parser 
is correct. An unprefixed attribute is *never* in a namespace, not 
the default namespace, not the namespace of its parent element, no 
namespace ever.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          XML in a  Nutshell, 2nd Edition (O'Reilly, 2002)          |
|              http://www.cafeconleche.org/books/xian2/              |
|  http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/  |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.cafeconleche.org/    |
+----------------------------------+---------------------------------+

---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org


Re: Problem with attribute namespaces

Posted by robert burrell donkin <ro...@mac.com>.
hi brenda

this is probably the wrong list to ask this kind of question. this is a 
SAX question and you're probably better off asking on a SAX list. even if 
it were a parser problem, then you should ask on the user list for the 
parser that you're using.

anyway, you're lucky since i think i might be able to help you. i think 
that you're trying to get hold of namespace information. try setting the 
'http://xml.org/sax/features/namespace-prefixes' flag to true. (if you don'
t know how to do this - or it doesn't work - then ask on a SAX list.)

- robert

On Friday, July 12, 2002, at 08:46 PM, Brenda Bell wrote:

> I've used several different SAXParsers to parse the following document:
>
> <?xml version="1.0" encoding="utf-8"?>
> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
>   <soap:Body>
>     <businessList generic="1.0" operator="Microsoft Corporation" 
> truncated="false" xmlns="urn:uddi-org:api">
>       <businessInfos>
>         <businessInfo businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
>           <name>XMethods</name>
>           <description xml:lang="en">Web services resource 
> site</description>
>           <serviceInfos>
>             <serviceInfo serviceKey="d5b180a0-4342-11d5-bd6c-002035229c64"
>  businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
>
>               <name>XMethods Barnes and Noble Quote</name>
>             </serviceInfo>
>             <serviceInfo serviceKey="ed85f000-4345-11d5-bd6c-002035229c64"
>  businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
>
>               <name>XMethods Pacific Bell SMS Service</name>
>             </serviceInfo>
>             <serviceInfo serviceKey="d5921160-3e16-11d5-98bf-002035229c64"
>  businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
>
>               <name>XMethods Delayed Stock Quotes</name>
>             </serviceInfo>
>             <serviceInfo serviceKey="618167a0-3e64-11d5-98bf-002035229c64"
>  businessKey="ba744ed0-3aaf-11d5-80dc-002035229c64">
>
>               <name>XMethods Currency Exchange Rates</name>
>             </serviceInfo>
>           </serviceInfos>
>         </businessInfo>
>       </businessInfos>
>     </businessList>
>   </soap:Body>
> </soap:Envelope>
>
> Where I'm having a problem is in my handler's startElement implementation.
>   Seems that attributes(idx).getURI() always returns an empty string.  
> For an attribute like businessKey, I would have expected the default URI 
> "urn:uddi-org:api".
>
> Is this a bug in the parser?  Or am I doing something wrong?
>


---------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
For additional commands, e-mail: general-help@xml.apache.org