function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bbradybbrady 

What it the best way to upload and process a file containing XML?

My ultimate goal is to take XML generated by a VF page and hand it off to a charting library (AnyChart).

 

As an initial test, I uploaded the AnyChart demo XML as a static resource and was successful parsing it using the code below. However when I put the identical 'demo XML' into a VF page I was unsuccessful using either the hard path to the VF page (i.e. '/apex/AnyChartXML') or a reference to the same page (i.e. "{!$Page.AnychartXML}")

 

Based on a response to a related post I believe that '/apex/AnyChartXML' should reference the appropriate page, No?

 

 

<apex:page showHeader="false">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" language="javascript">

function loadXMLDoc(dname)
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e) {alert(e.message)}
}
try
{
xmlDoc.async=false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e) {alert(e.message)}
return(null);
}
</script>
</head>
<body>
<script type="text/javascript" language="javascript">
loadXMLDoc("{!$Resource.AnyChartXML}");
// loadXMLDoc("/apex/AnychartXML");
// loadXMLDoc("{!$Page.AnychartXML}");

x=xmlDoc.getElementsByTagName("text");
for (i=0;i<x.length;i++)
{
document.write(x[i].childNodes[0].nodeValue);
document.write("<br />");
}

</script>
</body>
</html>
</apex:page>

 

 

Here is the code for the VF page (/apex/AnyChartXML) containing the XML (the controller is used to populate merge fields not yet used on this page).

 

 

<apex:page controller="AssetXMLcon" showheader="false" contenttype="text/xml; charset=UTF-8">
<anychart>
<charts>
<chart plot_type="CategorizedHorizontal">
<data>
<series name="Year 2003" type="Bar">
<point name="Department Stores" y="637166" />
<point name="Discount Stores" y="721630" />
<point name="Men's/Women's Specialty Stores" y="148662" />
<point name="Juvenile Specialty Stores" y="78662" />
<point name="All other outlets" y="90000" />
</series>
</data>
<chart_settings>
<title>
<text>Sales of ACME Corp.</text>
</title>
<axes>
<y_axis>
<title>
<text>Sales</text>
</title>
</y_axis>
<x_axis>
<labels align="Outside" />
<title>
<text>Retail Channel</text>
</title>
</x_axis>
</axes>
</chart_settings>
</chart>
</charts>
</anychart>
</apex:page>