title: How to add Image using CDATA tag in KML / XML?
body: <p>I'm creating an android application where I need to create KML file which have Location title , location description &amp; Image of location . 
  As of now I have managed to add Title &amp; description to Kml file &amp; it is working perfectly fine but I'm not able to find any solution where I can add Image into KML file using JAVA .</p>
  
  <p>Here is code of creating KML file :</p>
  
  <pre><code>public void generateKMLFile()
  {
      try {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      DocumentBuilder builder = factory.newDocumentBuilder();
      TransformerFactory tranFactory = TransformerFactory.newInstance();
      Transformer aTransformer = tranFactory.newTransformer();
      Document doc = builder.newDocument();
      Element root = doc.createElement("kml");
      root.setAttribute("xmlns", "http://earth.google.com/kml/2.1");
      doc.appendChild(root);
      Element dnode = doc.createElement("Document");
      root.appendChild(dnode);
      Element rstyle = doc.createElement("Style");
      rstyle.setAttribute("id", "restaurantStyle");
      Element ristyle = doc.createElement("IconStyle");
      ristyle.setAttribute("id", "restaurantIcon");
      Element ricon = doc.createElement("Icon");
      Element riconhref = doc.createElement("href");
      riconhref.appendChild(doc.createTextNode("http://maps.google.com/mapfiles/kml/pal2/icon63.png"));
      rstyle.appendChild(ristyle);
      ricon.appendChild(riconhref);
      ristyle.appendChild(ricon);
      dnode.appendChild(rstyle);
      Element bstyle = doc.createElement("Style");
      bstyle.setAttribute("id", "barStyle");
      Element bistyle = doc.createElement("IconStyle");
      bistyle.setAttribute("id", "barIcon");
      Element bicon = doc.createElement("Icon");
      Element biconhref = doc.createElement("href");
      biconhref.appendChild(doc.createTextNode("http://maps.google.com/mapfiles/kml/pal2/icon27.png"));
      bstyle.appendChild(bistyle);
      bicon.appendChild(biconhref);
      bistyle.appendChild(bicon);
      dnode.appendChild(bstyle);
  
      Cursor c = mDatabaseManager.getAllLocations();
      while (c.moveToNext())
      {
          LocationBean lb = new LocationBean();
          lb.locationTitle = c.getString(c.getColumnIndex(DatabaseManager.LOCATION_TITLE));
          lb.lat = c.getDouble(c.getColumnIndex(DatabaseManager.LOCATION_LATITUDE));
          lb.log = c.getDouble(c.getColumnIndex(DatabaseManager.LOCATION_LONGITUDE));
          lb.remark = c.getString(c.getColumnIndex(DatabaseManager.LOCATION_REMARK));
  
  
          Element placemark = doc.createElement("Placemark");
          dnode.appendChild(placemark);
          Element name = doc.createElement("name");
          name.appendChild(doc.createTextNode(lb.locationTitle));
          placemark.appendChild(name);
          Element descrip = doc.createElement("description");
          descrip.appendChild(doc.createTextNode(lb.remark));
          placemark.appendChild(descrip);
          Element styleUrl = doc.createElement("styleUrl");
          styleUrl.appendChild(doc.createTextNode( "#" +lb.locationTitle+ "Style"));
          placemark.appendChild(styleUrl);
          Element point = doc.createElement("Point");
          Element coordinates = doc.createElement("coordinates");
          coordinates.appendChild(doc.createTextNode(lb.log+ "," + lb.lat));
          point.appendChild(coordinates);
          placemark.appendChild(point);
  
      }
  
      Source src = new DOMSource(doc);
      Result dest = new StreamResult(new File("/sdcard/PlaceMarkers.kml")); // temporarily directly saved to sdcard
      aTransformer.transform(src, dest);
      System.out.println("Completed.....");
  
  
  }
  catch (ParserConfigurationException e) {
      e.printStackTrace();
  } catch (TransformerConfigurationException e) {
      e.printStackTrace();
  } catch (TransformerException e) {
      e.printStackTrace();
  }
  
  
  }
  </code></pre>
  
  <p>And here is snippet of reference KML file which have image data (hosted on google cloud) within CDATA tag so , I thought we can add something like image data within CDATA tag from JAVA APIs:</p>
  
  <pre><code>&lt;Placemark&gt;
      &lt;name&gt;Home&lt;/name&gt;
      &lt;description&gt;&lt;![CDATA[&lt;img src="https://lh4.googleusercontent.com/6-eAD3dYM1l4nBR5lQOZ3XLWmPuZ0juf4kgPqQykrJw0rTIo17TZQIc_1G1Jg4AuAV2M5xB4HBHB6x4WaHG4H4zQXCqeKonhmHm05AqLZsbhlIAmQyzFfzfpTaDmoVzoLQ" height="200" width="auto" /&gt;&lt;br&gt;&lt;br&gt;My HOme]]&gt;&lt;/description&gt;
      &lt;styleUrl&gt;#icon-1899-0288D1&lt;/styleUrl&gt;
      &lt;ExtendedData&gt;
        &lt;Data name="gx_media_links"&gt;
          &lt;value&gt;https://lh4.googleusercontent.com/6-eAD3dYM1l4nBR5lQOZ3XLWmPuZ0juf4kgPqQykrJw0rTIo17TZQIc_1G1Jg4AuAV2M5xB4HBHB6x4WaHG4H4zQXCqeKonhmHm05AqLZsbhlIAmQyzFfzfpTaDmoVzoLQ&lt;/value&gt;
        &lt;/Data&gt;
      &lt;/ExtendedData&gt;
      &lt;Point&gt;
        &lt;coordinates&gt;
          73.1988519,22.2953976,0
        &lt;/coordinates&gt;
      &lt;/Point&gt;
    &lt;/Placemark&gt;
  </code></pre>
  
  <p>All data i.e location name , location description , latitude , longitude &amp; images are stored in SQLite db &amp; creating KML file from these data.</p>
  
  <p>I have asked question as KML / XML it is because if we can create in XML then it is possible for the KML so , any suggestions on this ?</p>