xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Glavassevich <mrgla...@ca.ibm.com>
Subject Re: Add namespaces declaration to parent element.
Date Thu, 20 Aug 2009 11:56:15 GMT
Hello,

The value of the 2nd parameter of setAttributeNS() [1] is supposed to be a
qualified named and needs to start with "xmlns:" or be "xmlns" for a
namespace declaration.

Try:

parent.setAttributeNS
(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,"xmlns:"+prefix,desc.getNamespaceURI
());

instead of:

parent.setAttributeNS
(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,prefix,desc.getNamespaceURI());

Thanks.

[1]
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#ID-ElSetAttrNS

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com);
E-mail: mrglavas@apache.org

juho <j.houllier@gmail.com> wrote on 08/20/2009 04:57:05 AM:

> Hello,
>
> I want to add namespaces declaration on parent if child and parent have
> different namespaces.
> My wish is to have output like that:
>
> <balise1 xmlns:tec="http://test1">
>   <tec:balise2 />
>   <tec:balise3 />
> </balise>
>
> instead of what i have actually
> <balise1>
>   <tec:balise2 xmlns:tec="http://test1"/>
>   <tec:balise3 xmlns:tec="http://test1"/>
> </balise1>
>
> I tried to obtain that with
>
> parent.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,prefix,
> desc.getNamespaceURI());
>
> but it generates exception :
> org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or
> change an object in a way which is incorrect with regard to namespaces.
>    at org.apache.xerces.dom.AttrNSImpl.setName(Unknown Source)
>    at org.apache.xerces.dom.AttrNSImpl.<init>(Unknown Source)
>    at org.apache.xerces.dom.PSVIAttrNSImpl.<init>(Unknown Source)
>    at org.apache.xerces.dom.PSVIDocumentImpl.createAttributeNS(Unknown
Source)
>    at org.apache.xerces.dom.ElementImpl.setAttributeNS(Unknown Source)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> createElement(DocumentBuilderFromXSD.java:261)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> setMandatories(DocumentBuilderFromXSD.java:333)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> createElement(DocumentBuilderFromXSD.java:283)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> setMandatories(DocumentBuilderFromXSD.java:333)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> createElement(DocumentBuilderFromXSD.java:283)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> setMandatories(DocumentBuilderFromXSD.java:333)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> createElement(DocumentBuilderFromXSD.java:283)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> createRoot(DocumentBuilderFromXSD.java:130)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> <init>(DocumentBuilderFromXSD.java:81)
>    at
> org.tdf.tpegPlugin.parser.DocumentBuilderFromXSD.
> <init>(DocumentBuilderFromXSD.java:67)
>    at org.tdf.tpegPlugin.Main.main(Main.java:52)
> --
> View this message in context: http://www.nabble.com/Add-namespaces-
> declaration-to-parent-element.-tp25058380p25058380.html
> Sent from the Xerces - J - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org
Mime
View raw message