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
YallDevYallDev 

How to render a String that is in XML format which was return from a webservice.

Hi

 

I am very new with visualforce development, and I decided to learn by trying a weather webservice, however  what it returns

is a string, that looks like XML. I have no clue how to parse this. I have already found out that I must create a new class to capture it.

 

I would appreciate any tips or hints.

 

Below is what it returns.

 

<?xml version="1.0" encoding="utf-16"?> <CurrentWeather> <Location>Eindhoven, Netherlands (EHEH) 51-27N 005-25E 28M</Location> <Time>Jul 04, 2012 - 06:55 AM EDT / 2012.07.04 1055 UTC</Time> <Wind> from the S (180 degrees) at 5 MPH (4 KT):0</Wind> <Visibility> greater than 7 mile(s):0</Visibility> <SkyConditions> overcast</SkyConditions> <Temperature> 73 F (23 C)</Temperature> <DewPoint> 57 F (14 C)</DewPoint> <RelativeHumidity> 56%</RelativeHumidity> <Pressure> 29.91 in. Hg (1013 hPa)</Pressure> <Status>Success</Status> </CurrentWeather>

Best Answer chosen by Admin (Salesforce Developers) 
YallDevYallDev

Thanks It worked for me.

All Answers

JHayes SDJHayes SD

Assuming you have the value as a String, you can create an instance of the XmlStreamReader class and pass your value into the contstructor.  The docs: 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_xml_XmlStream_reader.htm

 

The examples in the documentation show how to traverse and access the elements in your XML data.  From there you can assign to object fields, etc.

 

Regards, jh 

 

 

 

YallDevYallDev

Thanks It worked for me.

This was selected as the best answer