title: Namespace error while converting Java to XML
body: <p>I'm trying to create an XML string like below using <code>Java</code>.</p>
  
  <pre><code>&lt;entry gd:etag="*" xmlns="http://www.w3.org/2005/Atom"&gt;
    &lt;id&gt;http://www.google.com/m8/feeds/contacts/default/base/contactid&lt;/id&gt;
    &lt;category scheme="http://schemas.google.com/g/2005#kind"
      term="http://schemas.google.com/contact/2008#contact"/&gt;
    &lt;gd:name&gt;
      &lt;gd:fullName&gt;{Name}&lt;/gd:fullName&gt;
    &lt;/gd:name&gt;
    &lt;gd:email rel="http://schemas.google.com/g/2005#work"
      primary="true"
      address="{Email}" displayName="Mani"/&gt;
    &lt;content type="text"&gt;Notes&lt;/content&gt;
    &lt;gd:phoneNumber rel="http://schemas.google.com/g/2005#other"
      primary="true"&gt;{MobileNumber}&lt;/gd:phoneNumber&gt;
  &lt;/entry&gt;
  </code></pre>
  
  <p>My java code is </p>
  
  <pre><code>DocumentBuilderFactory docBuildFactory = DocumentBuilderFactory.newInstance();  
  DocumentBuilder docBuilder = docBuildFactory.newDocumentBuilder();
  Document doc = docBuilder.newDocument();
  Element entry = doc.createElement("entry");
  entry.setPrefix("gd");  
  entry.setAttribute("gd:etag","*");
  doc.appendChild(entry);
  Element id = doc.createElement("id");
  id.setTextContent("http://www.google.com/m8/feeds/contacts/default/base/"+contactID);
  entry.appendChild(id);
  Element category = doc.createElement("catagory");
  category.setAttribute("scheme","http://schemas.google.com/g/2005#kind");
  category.setAttribute("term","http://schemas.google.com/contact/2008#contact");
  entry.appendChild(category);
  Element name = doc.createElement("gd:name");
  Element fullName = doc.createElement("gd:fullname");
  fullName.setTextContent(newName);
  name.appendChild(fullName);
  entry.appendChild(name);
  ....
  StringWriter stringWriter = new StringWriter();
  StreamResult result = new StreamResult(stringWriter);
  DOMSource source = new DOMSource(entry);
  TransformerFactory transformFactory = TransformerFactory.newInstance();
  Transformer transformer = transformFactory.newTransformer();
  transformer.transform(source , result);
  String xmlString = stringWriter.toString();
  </code></pre>
  
  <p>When I run the above code, I'm getting the following exceptions</p>
  
  <blockquote>
    <p>Exception in thread "main" 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.<br>
    at java.xml/com.sun.org.apache.xerces.internal.dom.NodeImpl.setPrefix()</p>
  </blockquote>
  
  <p>Can someone suggest me where I'm going wrong?</p>