title: How to escape XML null value?
body: <p>Im having this problem. I Have an XML data but not in .xml format.</p>
  
  <p>I need to display the result based on keyword for search, then it returns the value in xml format. But, there are some nodes that do not contains any value (null value). How do i escape this value ?</p>
  
  <p>I want to display the nodes that only have values (non null nodes). Thanks.</p>
  
  <p>This is my code. Im a beginner in java programming. I need help as much as I can. Thanks all !</p>
  
  <pre><code>DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
                  DocumentBuilder db = dbf.newDocumentBuilder();
                  InputSource is = new InputSource();
                  is.setCharacterStream(new StringReader(result));
                  Document doc = db.parse(is);
                  NodeList nodes = doc.getElementsByTagName("DOCUMENT");
  
                  // iterate the DOCUMENT                
                  out.println("&lt;table border='0'&gt;");
                  int index_location=nodes.getLength()+1;
                  for (int i = 0; i &lt; nodes.getLength(); i++) {
  
                      locations_array+="[";
  
                      Element element = (Element) nodes.item(i); 
  
                      NodeList IDS = element.getElementsByTagName("IDS");
                      Element line = (Element) IDS.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Company ID :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList FULL_NAME = element.getElementsByTagName("FULL_NAME");
                      line = (Element) FULL_NAME.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Company Name :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
                      locations_array+="'"+getCharacterDataFromElement(line)+"',";
  
                      NodeList AD_WEIGHT = element.getElementsByTagName("AD_WEIGHT");
                      line = (Element) AD_WEIGHT.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;AD_WEIGHT :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList MAP = element.getElementsByTagName("MAP");
                      line = (Element) MAP.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Longitude and Latitude :&lt;/td&gt;&lt;td&gt;");
  
                      if (getCharacterDataFromElement(line)!="No data provided."){
                          String st = getCharacterDataFromElement(line);
                          String str[] = st.split(":", 2);
                          String latlong;
                          latlong = str[1];
                          out.println(latlong);
                          locations_array+="'"+latlong+"',";
                      }else{
                          out.println("No data provided.");
                          locations_array+="'0,0',";
                      }
  
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList STATE = element.getElementsByTagName("STATE");
                      line = (Element) STATE.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;State :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList CITY = element.getElementsByTagName("CITY");
                      line = (Element) CITY.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;City :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList ADDRESS = element.getElementsByTagName("ADDRESS");
                      line = (Element) ADDRESS.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Address :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList PHONE = element.getElementsByTagName("PHONE");
                      line = (Element) PHONE.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Phone No :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList CLASS_DESC = element.getElementsByTagName("CLASS_DESC");
                      line = (Element) CLASS_DESC.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;CLASS_DESC :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList MAIN_CLASS = element.getElementsByTagName("MAIN_CLASS");
                      line = (Element) MAIN_CLASS.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Category :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList URL = element.getElementsByTagName("URL");
                      line = (Element) URL.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Website :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList EMAIL = element.getElementsByTagName("EMAIL");
                      line = (Element) EMAIL.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;Email :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList DISPLAY_AD = element.getElementsByTagName("DISPLAY_AD");
                      line = (Element) DISPLAY_AD.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;DISPLAY_AD :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList ADV_PATH = element.getElementsByTagName("ADV_PATH");
                      line = (Element) ADV_PATH.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;ADV_PATH :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList SORT_NO = element.getElementsByTagName("SORT_NO");
                      line = (Element) SORT_NO.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;SORT_NO :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      NodeList TOTAL_ADDRESS = element.getElementsByTagName("TOTAL_ADDRESS");
                      line = (Element) TOTAL_ADDRESS.item(0);
                      out.println("&lt;tr&gt;&lt;td&gt;TOTAL_ADDRESS :&lt;/td&gt;&lt;td&gt;");
                      out.println(getCharacterDataFromElement(line));
                      out.println("&lt;/td&gt;&lt;/tr&gt;");
  
                      out.println("&lt;tr&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;td&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;");
  
                      index_location--;
                      locations_array+="'"+index_location+"']";
                      //locations_array+=",";                    
                  }
                  out.println("&lt;/table&gt;");
  </code></pre>
  
  <p>This is the sample xml</p>
  
  <pre><code>&lt;DOCUMENT&gt;
            &lt;IDS&gt;53850_WP&lt;/IDS&gt;
            &lt;FULL_NAME&gt;xxx&lt;/FULL_NAME&gt;
            &lt;AD_WEIGHT&gt;60&lt;/AD_WEIGHT&gt;
            &lt;MAP&gt;1111:1.12344556,111.67890&lt;/MAP&gt;
            &lt;STATE&gt;xxx xxx&lt;/STATE&gt;
            &lt;CITY&gt;xxxx&lt;/CITY&gt;
            &lt;ADDRESS&gt;123 xxx xxxx xxx&lt;/ADDRESS&gt;
            &lt;PHONE&gt;12-12344551&lt;/PHONE&gt;
            &lt;CLASS_DESC&gt;Banks&lt;/CLASS_DESC&gt;
            &lt;MAIN_CLASS&gt;Banks&lt;/MAIN_CLASS&gt;
            &lt;URL&gt;www.qwe.com&lt;/URL&gt;
            &lt;EMAIL&gt;qwer@qwe.com&lt;/EMAIL&gt;
            &lt;DISPLAY_AD /&gt;
            &lt;ADV_PATH /&gt;
            &lt;SORT_NO&gt;123&lt;/SORT_NO&gt;
            &lt;TOTAL_ADDRESS&gt;123&lt;/TOTAL_ADDRESS&gt;
            &lt;INLINE_IMAGE /&gt;
            &lt;E_PRODUCT /&gt;
            &lt;FIELD1 /&gt;
          &lt;/DOCUMENT&gt;
  </code></pre>
  
  <p>From the sample, there are null nodes like <code>&lt;INLINE_IMAGE&gt;</code>, <code>&lt;E_PRODUCT&gt;</code> and <code>&lt;FIELD1&gt;</code>. How do i escape this from display in the result page ?</p>