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
RAJNagRAJNag 

Please write page anyone in below code

Hi

I wrote One soap class i checked developer consloe its displyed country and state values .

//Generated by wsdl2apex

public class GlobalWhetherClass {
    public class GetWeather_element {
        public String CityName;
        public String CountryName;
        private String[] CityName_type_info = new String[]{'CityName','http://www.webserviceX.NET',null,'0','1','false'};
        private String[] CountryName_type_info = new String[]{'CountryName','http://www.webserviceX.NET',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'CityName','CountryName'};
    }
    public class GetCitiesByCountry_element {
        public String CountryName;
        private String[] CountryName_type_info = new String[]{'CountryName','http://www.webserviceX.NET',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'CountryName'};
    }
    public class GetWeatherResponse_element {
        public String GetWeatherResult;
        private String[] GetWeatherResult_type_info = new String[]{'GetWeatherResult','http://www.webserviceX.NET',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'GetWeatherResult'};
    }
    public class GetCitiesByCountryResponse_element {
        public String GetCitiesByCountryResult;
        private String[] GetCitiesByCountryResult_type_info = new String[]{'GetCitiesByCountryResult','http://www.webserviceX.NET',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'GetCitiesByCountryResult'};
    }
    public class GlobalWeatherSoap {
        public String endpoint_x = 'http://www.webservicex.com/globalweather.asmx';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://www.webserviceX.NET', 'GlobalWhetherClass'};
        public String GetCitiesByCountry(String CountryName) {
            GlobalWhetherClass.GetCitiesByCountry_element request_x = new GlobalWhetherClass.GetCitiesByCountry_element();
            request_x.CountryName = CountryName;
            GlobalWhetherClass.GetCitiesByCountryResponse_element response_x;
            Map<String, GlobalWhetherClass.GetCitiesByCountryResponse_element> response_map_x = new Map<String, GlobalWhetherClass.GetCitiesByCountryResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/GetCitiesByCountry',
              'http://www.webserviceX.NET',
              'GetCitiesByCountry',
              'http://www.webserviceX.NET',
              'GetCitiesByCountryResponse',
              'GlobalWhetherClass.GetCitiesByCountryResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetCitiesByCountryResult;
        }
        public String GetWeather(String CityName,String CountryName) {
            GlobalWhetherClass.GetWeather_element request_x = new GlobalWhetherClass.GetWeather_element();
            request_x.CityName = CityName;
            request_x.CountryName = CountryName;
            GlobalWhetherClass.GetWeatherResponse_element response_x;
            Map<String, GlobalWhetherClass.GetWeatherResponse_element> response_map_x = new Map<String, GlobalWhetherClass.GetWeatherResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/GetWeather',
              'http://www.webserviceX.NET',
              'GetWeather',
              'http://www.webserviceX.NET',
              'GetWeatherResponse',
              'GlobalWhetherClass.GetWeatherResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetWeatherResult;
        }
    }
}

but new requirement is whenever select the country then display the state values in visualforce page .

Thanks in advance
Raj
Amit Chaudhary 8Amit Chaudhary 8
Please try below code. I am not sure this will help you or not. I created same code in 2013.
 
//Generated by wsdl2apex

public class wwwWebservicexNet {
    public class GetWeather_element {
        public String CityName;
        public String CountryName;
        private String[] CityName_type_info = new String[]{'CityName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] CountryName_type_info = new String[]{'CountryName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'CityName','CountryName'};
    }
    public class GetCitiesByCountry_element {
        public String CountryName;
        private String[] CountryName_type_info = new String[]{'CountryName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'CountryName'};
    }
    public class GlobalWeatherSoap {
        public String endpoint_x = 'http://www.webservicex.net/globalweather.asmx';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCertName_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://www.webserviceX.NET', 'wwwWebservicexNet'};
        public String GetCitiesByCountry(String CountryName) {
            wwwWebservicexNet.GetCitiesByCountry_element request_x = new wwwWebservicexNet.GetCitiesByCountry_element();
            wwwWebservicexNet.GetCitiesByCountryResponse_element response_x;
            request_x.CountryName = CountryName;
            Map<String, wwwWebservicexNet.GetCitiesByCountryResponse_element> response_map_x = new Map<String, wwwWebservicexNet.GetCitiesByCountryResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/GetCitiesByCountry',
              'http://www.webserviceX.NET',
              'GetCitiesByCountry',
              'http://www.webserviceX.NET',
              'GetCitiesByCountryResponse',
              'wwwWebservicexNet.GetCitiesByCountryResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetCitiesByCountryResult;
        }
        public String GetWeather(String CityName,String CountryName) {
            wwwWebservicexNet.GetWeather_element request_x = new wwwWebservicexNet.GetWeather_element();
            wwwWebservicexNet.GetWeatherResponse_element response_x;
            request_x.CityName = CityName;
            request_x.CountryName = CountryName;
            Map<String, wwwWebservicexNet.GetWeatherResponse_element> response_map_x = new Map<String, wwwWebservicexNet.GetWeatherResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.webserviceX.NET/GetWeather',
              'http://www.webserviceX.NET',
              'GetWeather',
              'http://www.webserviceX.NET',
              'GetWeatherResponse',
              'wwwWebservicexNet.GetWeatherResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.GetWeatherResult;
        }
    }
    public class GetWeatherResponse_element {
        public String GetWeatherResult;
        private String[] GetWeatherResult_type_info = new String[]{'GetWeatherResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'GetWeatherResult'};
    }
    public class GetCitiesByCountryResponse_element {
        public String GetCitiesByCountryResult;
        private String[] GetCitiesByCountryResult_type_info = new String[]{'GetCitiesByCountryResult','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.webserviceX.NET','true','false'};
        private String[] field_order_type_info = new String[]{'GetCitiesByCountryResult'};
    }
}
 
public class clsWebService 
{
    public string strCities {get;set;}
    
    //public List<clsWrap> lstWrap {get;set;}
    
    public class CountryWrap
    {
        public string Country {get;set;}
        public string City {get;set;}

        public CountryWrap()
        {
        }
                
        public CountryWrap(string pCountry, string pCity)
        {
            Country = pCountry;
            City = pCity;
        }
    }
    
    public void FetchCities()
    {
    /*
        //wwwWebservicexNet.GetCitiesByCountry_element  element=new wwwWebservicexNet.GetCitiesByCountry_element();
        //element.CountryName='INDIA';
        //wwwWebservicexNet.GetCitiesByCountryResponse_element resPOnseElement=new wwwWebservicexNet.GetCitiesByCountryResponse_element();
        lstWrap = new List<clsWrap>();
        wwwWebservicexNet.GlobalWeatherSoap Req=new wwwWebservicexNet.GlobalWeatherSoap();
        strCities = Req.GetCitiesByCountry('INDIA');
        system.debug('----->'+ strCities );
        strCities = strCities.replace('</','');
        strCities = strCities.replace('<','');
        strCities = strCities.replace('>','');
        strCities = strCities.replace('NewDataSet','');
        strCities = strCities.replace(' Table  Table ','');

        strCities = strCities.replace('Country','&');
        strCities = strCities.replace('City','&');
        //strCities = strCities.replace('*    *','*');
        List<string> lst = strCities.split('Table');
        
        
        for(integer i =0; i<lst.size(); i++)
        {
            if(lst[i].contains('&'))
            {
                List<string> brk = lst[i].trim().split('&');
                lstWrap.add(new clsWrap(brk[0],brk[2]));
            }
        }
        system.debug('***************lstWrap::::'+lstWrap);
        
        //*British Indian Ocean Territory * *Diego Garcia*
        
        //strCities = strCities.replace('Table','tr');
        //strCities = strCities.replace('City','td');
        //strCities = strCities.replace('Country','td');
        //strCities = strCities.replace('NewDataSet','table');
        
        //    </Table> <Table>
        
        //system.debug('Response=============' + Req.GetCitiesByCountry('INDIA'));
        
        */
        
        wwwWebservicexNet.GlobalWeatherSoap Req=new wwwWebservicexNet.GlobalWeatherSoap();
        String  strCities = Req.GetCitiesByCountry('india');
        //  system.debug('----->'+ strCities );
        XmlStreamReader xsr = new XmlStreamReader(strCities);
        
        CountryWrap[] CountryS = parseCountryS( xsr );
        
        System.debug('------------->'+CountryS);
        
    }
    
    public CountryWrap[] parseCountryS(XmlStreamReader reader) {
        
        CountryWrap[] CountryS= new CountryWrap[0];
        boolean isSafeToGetNextXmlElement = true;
        
        while(isSafeToGetNextXmlElement) 
        {
            // Start at the beginning of the book and make sure that it is a book
            
            if (reader.getEventType() == XmlTag.START_ELEMENT) 
            {
                if ('Table' == reader.getLocalName()) 
                {
                 System.debug('-Table-------------->'+reader.getLocalName() );
                    // Pass the Table to the parseBook method (below) 
                    CountryWrap obj= parseCountry(reader);
                    CountryS.add(obj);
                }
            }
            // Always use hasNext() before calling next() to confirm 
            // that we have not reached the end of the stream
            if (reader.hasNext()) 
            {
                reader.next();
            } 
            else 
            {
                isSafeToGetNextXmlElement = false;
                break;
            }
        }
        return CountryS;
    }
    
      // Parse through the XML, determine the author and the characters
    
    CountryWrap  parseCountry(XmlStreamReader reader) 
    {
        CountryWrap  obj= new CountryWrap();
       // System.debug( ' reader.getAttributeValue(null, city)------>'+ reader.getAttributeValue(null,'City') );
       // obj.Country  = reader.getAttributeValue(null, 'City');

        boolean isSafeToGetNextXmlElement = true;
        Integer i =0 ; 
        while(isSafeToGetNextXmlElement) 
        {

            if (reader.getEventType() == XmlTag.END_ELEMENT) 
            {
                i++;
                if(i > 2)
                {
                    break;
                }
            } else if (reader.getEventType() == XmlTag.CHARACTERS) 
            {
                if(i == 0)
                {
                    System.debug(i+'-Country-------------->'+reader.getText() );
                    obj.Country =  reader.getText();
                }
                else if( i == 1 )
                {
                    System.debug(i+'-City -------------->'+reader.getText() );
                    obj.City = reader.getText();
                }
            }
            // Always use hasNext() before calling next() to confirm 
            // that we have not reached the end of the stream
            if (reader.hasNext()) {
                reader.next();
            } else {
                isSafeToGetNextXmlElement = false;
                break;
            }
        }
        return obj;
    }
    
}
 
<apex:page controller="clsWebService">
    <apex:form >
        <apex:commandButton value="Call Service" action="{!FetchCities}" reRender="lbl"/>
        <apex:outputLabel escape="false" id="lbl"> {!strCities} </apex:outputLabel>
        
        
    </apex:form>
</apex:page>

NOTE:- You need to modify above code according to your requirement

Please let us know if this will help you.

Thanks,
Amit Chaudhary