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
MikeBates.ax895MikeBates.ax895 

Parsing XML

I have setup a REST API on an external application. I'm trying to use it to display information in force.com.

 

The XML returned is similar to this

<procedures>
    <procedure id="201011201" distribution_centre_id="2" hospital_id="143" date_booked="2011-01-25 00:00:00">
        <procedure_sales id="9892" procedure_id="201011201" person_id="212">
        </procedure_sales>
        <procedure_surgeon id="9893" procedure_id="201011201" person_id="580">
        </procedure_surgeon>
    </procedure>
    <procedure id="201012022" distribution_centre_id="2" hospital_id="152" date_booked="2011-01-12 00:00:00">
        <procedure_sales id="10042" procedure_id="201012022" person_id="199">
        </procedure_sales>
        <procedure_surgeon id="10043" procedure_id="201012022" person_id="1013">
        </procedure_surgeon>
    </procedure>
</procedures>

 

I'm trying to get it to output this basic data in html something like this to start

 

<div><p>Procedure Id : 201011201</p><p>Surgeon Id : 9893</p></div>

<div><p>Procedure Id : 201012022</p><p>Surgeon Id : 10043</p></div>

 

On my page I have this

 

 <apex:outputText value="{!Procedures}" escape="false"/>

 

and in my controller I have this method

 

 public String getProcedures() {
    
        String procedureString = '';
        
        if (this.theXMLDom != null && this.theXMLDom.getElementsByTagName('procedure') != null) {
            
            XmlDom.Element[] procedures = this.theXMLDom.getElementsByTagName('procedure');
            
            if( procedures != null ) {
                procedureString =+ '<div>Procedures</div>';
                for( XmlDom.Element procedure : procedures ) {
                    procedureString =+ '.';
                    procedureString =+ procedure.getValue('id');
                }
            }
        }
        return procedureString;
    }

 

I was hoping that would give me this output

<div>Procedures</div>.201011201.201012022

 

but I only get this

<div>Procedures</div>

 

how can I loop though the xml nodes and to get at the data?

 

(I'm using the XMLDom class)

 

Thanks for any help.

Mike

 

 

MikeBates.ax895MikeBates.ax895

I sorted this out.

 

My request call was not setup corectly

 

I was using

req.setEndpoint('http://staging.opskwan.com/api_procedures.xml')

req.setHeader('distribution_centre_id','2');

 

instead of

req.setEndpoint('http://staging.opskwan.com/api_procedures.xml?distribution_centre_id=2');

 

I'll have to read up on how to send and acceot header options properly