dataXML method

In our previous example, we had used the dataURL method to provide data to FusionMaps. In dataURL method, the data is contained in an external physical XML document (like Data.xml) or relayed by a URL (like ReturnXMLData.asp).

There also exists another method to provide the XML data to FusionMaps - dataXML method.

In this method, the XML Data exists in the same HTML page in which FusionMaps is embedded. When working with this method, you don't need to create the external XML document (like Data.xml). Instead you provide it in the HTML page.

Let's quickly see an example of the above.

 
Using dataXML method
Create a copy of our previous FirstMap.html and name it as DataXMLMap.html with the following code:

<html>
<head>
   <title>My First Map using dataXML Method</title>
   <script language="JavaScript" src="FusionMaps.js"></script>
</head>

<body>    
   <div id="mapdiv" align="center">
      FusionMaps.
   </div>
   <script type="text/javascript">
      var map = new FusionMaps("FCMap_World.swf", "Map1Id", "750", "400", "0", "0");
      map.setDataXML("<map borderColor='005879' fillColor='D7F4FF' numberSuffix=' Mill.' includeValueInLabels='1' labelSepChar=': ' baseFontSize='9'><data> <entity id='NA' value='515' /><entity id='SA' value='373' /><entity id='AS' value='3875' /><entity id='EU' value='727' /><entity id='AF' value='885' /><entity id='AU' value='32' /></data></map>");
      map.render("mapdiv");
   </script>
</body>
</html>

You can clearly see above, that instead of using setDataURL method to provide the path of XML file, here we've used setDataXML method to provide the full XML data itself.

When you now view the map, you'll get the same output as before.

 
With this method, however, there can sometimes be problems when you're working with larger chunks of data. This problem happens due to the limitation on dataXML string length imposed by the browser. When you specify a larger chunk of data using dataXML method, the browser ignores everything after a certain length. This causes FusionMaps to hang (nothing would be displayed on-screen) as the full data has not been supplied to it. Therefore, dataURL method is recommended for larger chunks of data.