title: Error writing a XML file in java
body: <p>I am trying to write an xml file using Java and I want to send a variable string to the method document.createElement(var) ,but it gives me that error:</p>
  
  <pre><code>"Exception in thread "main" org.w3c.dom.DOMException: INVALID_CHARACTER_ERR: An invalid or illegal XML character is specified. 
      at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createElement(Unknown Source)
      at eg.edu.alexu.csd.oop.draw.WriteXML.&lt;init&gt;(WriteXML.java:47)
      at eg.edu.alexu.csd.oop.draw.Test.main(Test.java:25)"
  </code></pre>
  
  <p>this error because var is a variable</p>
  
  <pre><code>public class WriteXML {
  
  public WriteXML() throws FileNotFoundException, ParserConfigurationException, IOException{
      DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
      DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
      Document xmlDoc = docBuilder.newDocument();
      for(int i=0 ; i&lt;shapes.length ; i++){
          //class
          s = shapes[i].getClass().getName().toString();
          Element rootElement =  xmlDoc.createElement(s);
  }
  </code></pre>