Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
2.8.1
-
None
Description
I have a requirement to generate an XML which should have empty namespace. An example XML should looks like:
<name xmlns:cap="mynamespace"> <cap:attributeID> <attribute1 xmlns="" >xxxx</attribute1> <attribute2 xmlns="" >xxxx</attribute2> </cap:attributeID> </name>
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:
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>.
element = doc.createElementNS("", "name"); // Output : <attribute1>xxxx</attribute1>
element = doc.createElement("name"); element.setAttribute("xmlns", ""); // Output : <attribute1>xxxx</attribute1>
element = doc.createElement("name"); element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", ""); // Output : <attribute1>xxxx</attribute1>
What is the correct way of adding an empty string as namespace to cater my requirement? Can someone provide guidance on this?
Thanks,
Vithursa