You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by Boris Garbuzov <bo...@keystrokenet.com> on 2000/03/29 18:44:15 UTC

setPrefix

    data = "data";
    CDATASectionImpl cDataSectionImpl = new CDATASectionImpl (documentImpl,
data);
    println ("NodeImpl's API");
    NodeImpl nodeImpl = (NodeImpl) cDataSectionImpl;

    String namespaceURI = nodeImpl.getNamespaceURI();
    println ("namespaceURI = " + namespaceURI);

    String prefix = nodeImpl.getPrefix();
    println ("prefix = " + prefix);

    Object userData = nodeImpl.getUserData();
    println ("userData = " + userData);

    prefix = "prefix";
    nodeImpl.setPrefix (prefix);

---------------
Why last statement of the above code produces the following error?
----------------

org.apache.xerces.dom.DOMExceptionImpl: DOM003 Namespace error
 at org.apache.xerces.dom.NodeImpl.setPrefix(NodeImpl.java:741)
 at com.keystrokenet.loanproduct.xml.test.Lab.executeTestBody(Lab.java:642)



--
Boris Garbuzov.
Mailing address:
Box 715, Seattle, Washington, 98111-0715, USA.
E-mail: garbuzov@hotmail.com, boris@keystroke.com.
Telephone: 1(206)781-5165 (home), 1(206)576-4549 (office).
Resedential address: 139 NW 104 Street, Seattle, 98177, Wa, USA



Re: setPrefix

Posted by Arnaud Le Hors <le...@us.ibm.com>.
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