Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am trying to create an attribute and set its value as,
Java
newElement = doc.createElement("SHORT-NAME");
newElement.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xsi", "http://www.w3.org/2001/XMLSchema");
attribute = doc.createAttribute("xsi:type");
attribute.setValue("VALUE");
newElement.setAttributeNode(attribute);

Java



Here I am expecting the output as,

XML
<SHORT-NAME xsi:type = "VALUE">


But I am getting the output,

XML
<SHORT-NAME xmlns:xsi = "http://www.w3.org/2001/XMLSchema" xsi:type = "VALUE>"


But here it is mandatory that I should provide a namespace for my attribute.

How to set the namespace attribute and get my expected result ?
Posted
Updated 29-Apr-14 18:33pm
v2

1 solution

how about

Java
newElement = doc.createElement("SHORT-NAME");
attribute = doc.createAttribute("xsi:type");
attribute.setValue("VALUE");
newElement.setAttributeNode(attribute);


does that work?
 
Share this answer
 
v2
Comments
Naveen Kinnal 5-May-14 7:42am    
no... it is asking to specify the namespace which is mandatory...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900