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
lesanglesang 

How to bind data into selectList?

Hi All,

I created an external web service it return an XML string format. Now I want to parse this XML string to bind data into selectList of Visual Force. My XML string:
<NewDataSet>
    <Properties diffgr:id="Properties1" msdata:rowOrder="0">
      <ProjectID>6949</ProjectID>
      <Description>All Metrics Example # 1</Description>
    </Properties>
    <Properties diffgr:id="Properties2" msdata:rowOrder="1">
      <ProjectID>6951</ProjectID>
      <Description>Test session</Description>
    </Properties>
</NewDataSet>

and my selectList has Text = Description and Value = ProjectID.

Any ideas?

Thanks so much.
Ron HessRon Hess
See xmlstream parser in the docs, i think it will allow you to parse this, then you can create the select elements from that data.
reshmareshma

First write a program to put the data in xml file in a custom object in this way

In the place of string str place your file here

here book__c is a custom object

public class Book

{

 public static void recordReplicator(Book__c[] book)

  {

   String str = '<books><book author="Manoj">Foo bar</book>' +'<book             author="Mysti">Baz</book></books>';

    XmlStreamReader reader = new XmlStreamReader(str);

    while(reader.hasNext())

     {

        if (reader.getEventType() == XmlTag.CHARACTERS)

        {

          for (Book__c b:book)

           {

               b.book_author__c = reader.getText();

               b.Name=reader.getText();

            }

          System.debug('Text :::' + reader.getText());

       }

         reader.next();

      }

        System.debug('Inside Book record replicator'+book);

  }

 }

 

Trigger on Book class

 

Setup->App setup->create->objects->book

 

In trigger section->add

trigger BookTrigger on Book__c (before insert) {
Book.recordReplicator(Trigger.new);
then the data is updated in the custom object.
from there write the following in apex page 
<apex:selectList size='1'><apex:selectOptions value="{!bookoptions}"/></apex:selectList>
in the controller
List<book__c> books=new List<book__c>();  
List<SelectOption> stateoptions = new List<SelectOption>();  
   
  books=[Select b.Name From book__c b];          
   String name1 ;   
  for(Integer j=0;j<books.size();j++)    
  {     
   name1=(books.get(j)).Name;       
   bookoptions.add(new SelectOption(name1,name1));     
  }   

public List<SelectOption> getStateoptions()   
 {   
  return stateoptions;   
 } 

It will work fine