[ 
https://issues.apache.org/jira/browse/XERCESJ-1720?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17016629#comment-17016629
 ] 

Vithursa commented on XERCESJ-1720:
-----------------------------------

Hi [~elharo],
{quote}xmlns="" is only needed when there's a default namespace in scope and 
you need to remove it.
{quote}
As you mentioned, my requirement is to add *xmlns = ""* in order to prevent  
default namespace getting added. Let me explain requirement in detail. I am 
generating an XML which should be appended as child for a root element, over 
which I do not have any control.

 Root element would have a format like this:
{code:xml}
<rootElement xmlns="defaultNamespace">
<!–The XML I generate, goes as a child of this-->
</rootElement>
{code}
My requirement is not add the root element's namespace to child. Since, I do 
not have any control over the root element, I am trying to add xmlns="" in 
child so that, it prevents the default namespace being added.

If I have root element as,
{code:xml}
<a xmlns:q="web">
 <q:b xmlns="">
   <r>123</r>
 </q:b>
</a>{code}
then it is possible that when appending the child element, the namespace of 
root element will not get added. Hence, I need to generate XML element with 
namespace *xmlns=""*.

Is it possible to do so?

Thanks,
 Vithursa

> Generate DOM Element with empty namespace using Apache xerces 
> --------------------------------------------------------------
>
>                 Key: XERCESJ-1720
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1720
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: Documentation
>    Affects Versions: 2.8.1
>            Reporter: Vithursa
>            Priority: Minor
>              Labels: query
>
> I have a requirement to generate an XML which should have empty namespace. An 
> example XML should looks like:
> {code:xml}
> <name  xmlns:cap="http://sap.com/xi/BASIS";>      
>    <cap:attributeID>            
>       <attribute1 xmlns="" >xxxx</attribute1>            
>       <attribute2 xmlns="" >xxxx</attribute2>      
>    </cap:attributeID> 
> </name>
> {code}
>  
>  As mentioned above, I need to add *xmlns* attribute with empty string. I 
> have tried following ways to achieve it but none of them worked:
> {code:java}
> DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
> DocumentBuilder docBuilder;
> docBuilder = docFactory.newDocumentBuilder();
> Document doc = docBuilder.newDocument(); 
> element = doc.createElement("attribute1");  // It did not have any namespace. 
> Output becomes as,  <attribute1>xxxx</attribute1>.
> {code}
> {code:java}
> element = doc.createElementNS("", "name"); // Output : 
> <attribute1>xxxx</attribute1>
> {code}
> {code:java}
> element = doc.createElement("name");
> element.setAttribute("xmlns", "");  // Output : <attribute1>xxxx</attribute1>
> {code}
> {code:java}
> element = doc.createElement("name");
> element.setAttributeNS("http://www.w3.org/2000/xmlns/";, "xmlns", "");
> // Output : <attribute1>xxxx</attribute1>
> {code}
> What is the correct way of adding an empty string as namespace to cater my 
> requirement? Can someone provide guidance on this?
> Thanks,
>  Vithursa



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: j-dev-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-dev-h...@xerces.apache.org

Reply via email to