+ Start a Discussion
SARI4SARI4 

Parse XML string and show on VF page in tabular format

Hi,

I have a XML response in string . I want to parse the response and show on VF page in table.
Below is my XML response.
<?xml version="1.0" encoding="UTF-8"?>
<FR>
   <STATUS>0</STATUS>
   <MSG />
   <ACCOUNTLIST>
      <ACCOUNT>
         <ACCOUNTID>1111</ACCOUNTID>
         <ACCOUNTNAME>ABC</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>2222</ACCOUNTID>
         <ACCOUNTNAME>BCD</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>3333</ACCOUNTID>
         <ACCOUNTNAME>Kurt</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>44444</ACCOUNTID>
         <ACCOUNTNAME>John</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>5555</ACCOUNTID>
         <ACCOUNTNAME>Kennedy</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>1212</ACCOUNTID>
         <ACCOUNTNAME>Model</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>232323</ACCOUNTID>
         <ACCOUNTNAME>ModelB</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>43434</ACCOUNTID>
         <ACCOUNTNAME>Eva</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>9876</ACCOUNTID>
         <ACCOUNTNAME>Marcel</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
      <ACCOUNT>
         <ACCOUNTID>1123</ACCOUNTID>
         <ACCOUNTNAME>Marc</ACCOUNTNAME>
         <DEFAULTDATE>20121231</DEFAULTDATE>
      </ACCOUNT>
   </ACCOUNTLIST>
</FR>


Please help me how to achive my requirnment.

Thanks
 

SARI4SARI4
I found the solution 
Apex class
public void parserclass(){
       AccountL=new list<AccountList>();
        Dom.Document doc = new Dom.Document();
        doc.load(xmlaccountlist);
        //Retrieve the root element for this document.
        dom.XmlNode xroot = doc.getrootelement() ;
        dom.XmlNode [] xrec = xroot.getchildelements() ;
        
        for(Dom.XMLNode child : xrec){ //Loop Through Records
              
          if(child.getname() == 'ACCOUNTLIST'){
           for (dom.XmlNode awr : child.getchildren() ) {
             if(awr.getname() == 'Account'){
                     AccountList acc=new AccountList();
                for (dom.XmlNode p : awr.getchildren() ) {
                      if (p.getname() == 'Accountid') 
                                   acc.Accountid=p.gettext();
                      if (p.getname() == 'Accountname') 
                                   acc.Accountname=p.gettext();
                      if (p.getname() == 'DEFAULTDATE')
                                   acc.defaultdate=p.gettext();    
                 }
                AccountL.add(acc); 
               }
            }
          }
                  
        }       
    }

VF page
<apex:pageblocktable value="{!accountL}" var="a">
      <apex:column value="{!a.accountid}" headerValue="AccountID"/>
      <apex:column value="{!a.accountName}" headerValue="Account Name"/>
      <apex:column value="{!a.defaultdate}" headerValue="Deafault Date"/>

  </apex:pageblocktable>