title: Fatal error : Character reference "&# org.xml.sax.SAXParseException;
body: <p>There is </p>
  
  <pre><code> &lt;BATCHNAME&gt;&amp;#4; Any&lt;/BATCHNAME&gt; 
  </code></pre>
  
  <p>tag in my xml request having '&#4;' characters in value. Without these characters my code works perfectly,but in some cases i have these characters. It gives me following error </p>
  
  <blockquote>
    <p>[Fatal Error] :144:28: Character reference "&amp;#
        org.xml.sax.SAXParseException; lineNumber: 144; columnNumber: 28; Character 
        reference "&amp;# at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:257)
      at
    com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
      at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:121)
      at d.b(AllCommonTasks.java:277)     at...</p>
  </blockquote>
  
  <p>I need these characters to be validate</p>
  
  <p>I am trying this code =></p>
  
  <pre><code>try {                      
  
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          DocumentBuilder db = dbf.newDocumentBuilder();
  
          URLConnection urlConnection = new URL(urlString).openConnection();
          urlConnection.addRequestProperty("Accept", "application/xml");
          urlConnection.addRequestProperty("User-Agent", "Mozilla/5.0 ( compatible ) ");
          Document doc = db.parse(urlConnection.getInputStream());
          doc.getDocumentElement().normalize();
  
          str = convertDocumentToString(doc);
  
  
      }catch(Exception e){
          System.err.println("In exception 1");
          e.printStackTrace();
      }
  </code></pre>
  
  <p>How can I solve this?</p>