title: How to add attributes to xml using XmlDocument in c# .net CF 3.5
body: <p>I need to create an attribute "abc" with the prefix "xx" for an element "aaa". The following code adds the prefix but it also adds the namespaceUri to the element.</p>
  
  <p>Required Output:</p>
  
  <pre><code>&lt;mybody&gt;
  &lt;aaa xx:abc="ddd"/&gt;
  &lt;mybody/&gt;
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>  XmlNode node = doc.SelectSingleNode("//mybody");
    XmlElement ele = doc.CreateElement("aaa");
  
    XmlAttribute newAttribute = doc.CreateAttribute("xx","abc",namespace);              
    newAttribute.Value = "ddd";
  
    ele.Attributes.Append(newAttribute);
  
    node.InsertBefore(ele, node.LastChild);
  </code></pre>
  
  <p>The above code generates :</p>
  
  <pre><code>&lt;mybody&gt;
  &lt;aaa xx:abc="ddd" xmlns:xx="http://www.w3.org/1999/XSL/Transform"/&gt;
  &lt;mybody/&gt;
  </code></pre>
  
  <p>Desired output is </p>
  
  <pre><code>&lt;mybody&gt;
  &lt;aaa xx:abc="ddd"/&gt;
  &lt;mybody/&gt;
  </code></pre>
  
  <p>And the declaration of the "xx" attribute should be done in the root node like : </p>
  
  <pre><code>&lt;ns:somexml xx:xsi="http://www.w3.org/1999/XSL/Transform"  xmlns:ns="http://x.y.z.com/Protocol/v1.0"&gt;
  </code></pre>
  
  <p>How can if get the output in the deisred format? If the xml is not in this desired format then it cannot be processed anymore..</p>
  
  <p>Can anyone help?</p>
  
  <p>Thanks,
  Vicky</p>