You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Gregor Karlinger <gr...@iaik.at> on 2000/07/03 17:28:54 UTC

Bug: Creating an attribute in a namespace

Hello!

I think I found another bug regarding the namespace implementation 
of a DOM attribute: 

Firstly I create a DOM Document instance of the following XML:

  <?xml version="1.0" encoding="UTF-8"?>

  <ns:root xmlns:ns="namespace">
    <ns:child ns:anAttribute="AttributeValue"/>
  </ns:root>

Now consider this code snipped:

  // Create a DOM Document from the XML above
  Element root = testDoc.getDocumentElement();
  NodeList children = root.getChildNodes();
  Element child = (Element)children.item(1);
  String attr = root.getAttributeNS("namespace", "anAttribute");

Unfortunately, the variable attr at the end of the code contains
a null reference instead of a String with value "AttributeValue".

Regards, Gregor
---------------------------------------------------------------
Gregor Karlinger
mailto://gregor.karlinger@iaik.at
http://www.iaik.at
Phone +43 316 873 5541
Institute for Applied Information Processing and Communications
Austria
---------------------------------------------------------------
 

RE: Bug: Creating an attribute in a namespace

Posted by Gregor Karlinger <gr...@iaik.at>.
> > Firstly I create a DOM Document instance of the following XML:
> > 
> >   <?xml version="1.0" encoding="UTF-8"?>
> > 
> >   <ns:root xmlns:ns="namespace">
> >     <ns:child ns:anAttribute="AttributeValue"/>
> >   </ns:root>

[...]

> Err. The attribute is on child not root! In addition, it's item(0)
> instead of item(1).

You are right, I pasted a old code fragment, the actual one asks for 
an attribute of child. Nevertheless, I still get the null reference
with the following code:

  Element root = testDoc.getDocumentElement();
  NodeList children = root.getChildNodes();
  Element child = (Element)children.item(1);
  NamedNodeMap attrs = child.getAttributes();
  String attr = child.getAttributeNS("namespace", "anAttribute");

I added another line to ask for all attributes of Element "child"
and did a litte search with the debugger. So I found out the following:

"attrs", which is of class AttributeMap, contains a single attribute
of class DeferredAttrNSImpl with this values for some member variables:

- localName: "anAttribute"
- name: "ns:anAttribute"
- namespaceURI: null

I think this is the problem. Since namespaceURI is null, the request
in the last line of the code fragment fails, since the namespace URI
passed in to method getAttributeNS is compared with this member 
variable "namespaceURI" (See NamedNodeMapImpl.java, line 511).

Apart from the bugfixed version of AttributeMap (Rev. 1.3) I am 
using Xerces 1.1.1.

Thanks, Gregor
---------------------------------------------------------------
Gregor Karlinger
mailto://gregor.karlinger@iaik.at
http://www.iaik.at
Phone +43 316 873 5541
Institute for Applied Information Processing and Communications
Austria
---------------------------------------------------------------
 

Re: Bug: Creating an attribute in a namespace

Posted by Arnaud Le Hors <le...@jtcsv.com>.
Gregor Karlinger wrote:
> 
> Hello!
> 
> I think I found another bug regarding the namespace implementation
> of a DOM attribute:
> 
> Firstly I create a DOM Document instance of the following XML:
> 
>   <?xml version="1.0" encoding="UTF-8"?>
> 
>   <ns:root xmlns:ns="namespace">
>     <ns:child ns:anAttribute="AttributeValue"/>
>   </ns:root>
> 
> Now consider this code snipped:
> 
>   // Create a DOM Document from the XML above
>   Element root = testDoc.getDocumentElement();
>   NodeList children = root.getChildNodes();
>   Element child = (Element)children.item(1);
>   String attr = root.getAttributeNS("namespace", "anAttribute");
> 
> Unfortunately, the variable attr at the end of the code contains
> a null reference instead of a String with value "AttributeValue".

Err. The attribute is on child not root! In addition, it's item(0)
instead of item(1).
--
Arnaud  Le Hors

Re: Creating an attribute in a namespace

Posted by Eric Ye <er...@locus.apache.org>.
I just tried with the latest source in CVS, can't reproduce the problem.
Which version of Xerces are you using?
_____


Eric Ye * IBM, JTC - Silicon Valley * ericye@locus.apache.org

----- Original Message -----
From: "Gregor Karlinger" <gr...@iaik.at>
To: "ML Xerces" <xe...@xml.apache.org>
Sent: Monday, July 03, 2000 8:28 AM
Subject: Bug: Creating an attribute in a namespace


> Hello!
>
> I think I found another bug regarding the namespace implementation
> of a DOM attribute:
>
> Firstly I create a DOM Document instance of the following XML:
>
>   <?xml version="1.0" encoding="UTF-8"?>
>
>   <ns:root xmlns:ns="namespace">
>     <ns:child ns:anAttribute="AttributeValue"/>
>   </ns:root>
>
> Now consider this code snipped:
>
>   // Create a DOM Document from the XML above
>   Element root = testDoc.getDocumentElement();
>   NodeList children = root.getChildNodes();
>   Element child = (Element)children.item(1);
>   String attr = root.getAttributeNS("namespace", "anAttribute");
>
> Unfortunately, the variable attr at the end of the code contains
> a null reference instead of a String with value "AttributeValue".
>
> Regards, Gregor
> ---------------------------------------------------------------
> Gregor Karlinger
> mailto://gregor.karlinger@iaik.at
> http://www.iaik.at
> Phone +43 316 873 5541
> Institute for Applied Information Processing and Communications
> Austria
> ---------------------------------------------------------------
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>
>