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
chantspelchantspel 

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:

 

 <Wrapper>
	<reportTable name='table_id' title='Report Title'>
      <row>
        <Element1><![CDATA[Activewear_2010_Campaigns]]></Element1>
        <Element2><![CDATA[577373]]></Element2>
        <Element3><![CDATA[4129]]></Element3>
        <Element4 dataFormat='2' dataSuffix='%'><![CDATA[0.7151]]></Element4>
        <Element5><![CDATA[2010-04-04]]></Element5>
        <Element6><![CDATA[2010-05-03]]></Element6>
      </row>
    </reportTable>
	...
</Wrapper>

 

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:

 

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

 

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.

 

 

 

DharmeshDharmesh

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