+ Start a Discussion

Consume XML and display in VF report

Firstly, this question requires a bit of introduction so please bear with me.


The high level is that I am connecting to a outside web service which will return some XML to my apex controller. The format will look something like this:


	<reportTable name='table_id' title='Report Title'>
        <Element4 dataFormat='2' dataSuffix='%'><![CDATA[0.7151]]></Element4>


Now currently I am using the XMLdom utility class to map this data into a custom object "report" which contains a list of "row" objects.


From there I need to display the report in a table output to VisualForce. Something like this I think will work:


  <apex:repeat value="{!reportTables}" var="table">
      <apex:repeat value="{!table.rows}" var="row">
      	<apex:repeat value="{!row.ColumnValue}" var="column">
      		<apex:repeat value="{!column}" var="value">
      			<apex:outputText value="{!value}" />


Now you may be wondering why I don't use something easier to work with like apex:pageBlockTable - the reason is I need to be able to handle a data coming back that contains different number of columns. So far I haven't been able to figure out a way to have apex:pageBlockTable handle my XML without explicitly knowning each column in advance.


Questions are:

1) Does this seem like a good approach to the problem?

2) Is there a simpler/better way to consume the XML besides writing my own custom objects to map VF to?


Open to any and all suggestions. I really hope there is a better way than building the HTML table myself, as then I also have to deal with styling and alignment etc. Thanks.





As far as I know for dynamic columns you need to user apex:repeat tag only.