title: Creating XML in javascript
body: <p>I have a React application where I need to create an XML string. The server takes the input in string format but the string looks like below:</p>
  
  <pre><code> &lt;preferences&gt;
      &lt;uid&gt;11130286&lt;/uid&gt;
            &lt;spotdays&gt;3&lt;/spotdays&gt;  
            &lt;defaultcomp&gt;26740&lt;/defaultcom&gt;
            &lt;defaultm&gt;    &lt;defaultm&gt;     
              &lt;comp&gt;3569&lt;/comp&gt;
              &lt;market&gt;29&lt;/market&gt;
           &lt;/defaultm&gt;    
           &lt;defaultm&gt;
              &lt;comp&gt;26740&lt;/comp&gt;
              &lt;market&gt;25&lt;/market&gt;    
           &lt;/defaultm&gt;
      &lt;bookmarks/&gt;
  &lt;/preferences&gt;    
  </code></pre>
  
  <p>The old code uses E4X (XML) to create this XML. It does not have the xmlns etc the way actual XML document has. What is the equivalent of using E4X in React? What do I need to use to create the above string in XML format?</p>
  
  <p>I am trying to do below: </p>
  
  <pre><code>    let doc = document.implementation.createDocument("", "", null); 
      let preferenceElem = doc.createElement("preferences"); 
      let userId = doc.createElement("userId"); 
      userId.setAttribute('userid', String(preference.userId)); 
  </code></pre>
  
  <p>but this gives me </p>
  
  <pre><code>   &lt;userId userId="67689"/&gt; 
  </code></pre>
  
  <p>I want to achieve </p>
  
  <pre><code>   &lt;userId&gt; 67890&lt;/userId&gt;. 
  </code></pre>
  
  <p>how do I achieve this? </p>