Boris Garbuzov wrote:
>
> data = "data";
> CDATASectionImpl cDataSectionImpl = new CDATASectionImpl
> (documentImpl, data);
> println ("NodeImpl's API");
> NodeImpl nodeImpl = (NodeImpl) cDataSectionImpl;
> ...
> prefix = "prefix";
> nodeImpl.setPrefix (prefix);
>
> ---------------
> Why last statement of the above code produces the following error?
> ----------------
>
> org.apache.xerces.dom.DOMExceptionImpl: DOM003 Namespace error
> ...
Because namespaces in general only apply to elements and attributes. So
in the DOM only Element and Attr nodes can have a namespaceURI and a
(namespace) prefix. Trying to set a prefix on another type of node is an
error.
Otherwise, I have two other comments on your code (no offense):
First, a CDATASectionImpl inherits from NodeImpl, so the cast:
> NodeImpl nodeImpl = (NodeImpl) cDataSectionImpl;
isn't necessary.
Second, unless you have a specific reason that isn't exposed in your
message, referring to *Impl classes all over the place like that isn't
necessary. Only a few things ("proprietary features") are only
accessible from the classes and require casting. Your sample would work
just using the standard interfaces:
> data = "data";
> CDATASection cDataSection = document.createCDATASection(data);
>
> String namespaceURI = cDataSection.getNamespaceURI();
> println ("namespaceURI = " + namespaceURI);
>
> String prefix = cDataSection.getPrefix();
> println ("prefix = " + prefix);
>
> // casting to access proprietary API
> Object userData = ((NodeImpl)cDataSection).getUserData();
> println ("userData = " + userData);
>
> prefix = "prefix";
> cDataSection.setPrefix (prefix);
Hope this helps.
--
Arnaud Le Hors - IBM Cupertino, XML Technology Group