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
Ashmi PatelAshmi Patel 

how tom use xml file in apex class

how can i connect xml file with apex class???

This is my Apex class:::

global class GoogleAppsRegistrationHandler implements Auth.RegistrationHandler
{
        global User createUser(Id portalId, Auth.UserData data)
        {
                         String email = data.email;
                        if (email == null) return null;

                            User u;
                            try {
                        u = [Select Id, FirstName, LastName, Email, Username from User Where Username = :email];
                                }  
                                   catch (Exception e){
                            return null;
                                                        }
                                            return u;
                                            }
global void updateUser(Id userId, Id portalId, Auth.UserData data){

}
}


This is my Xml file:::
 
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>27.0</apiVersion>
</ApexClass>
 
Best Answer chosen by Ashmi Patel
king s 8king s 8
This XML using  try this


public class parse{
    public void call(){
    String str=+'<?xml version="1.0" encoding="UTF-8"?>'
    +'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">'
    +'<apiVersion>27.0</apiVersion>'
    +'</ApexClass>';

    list<string> listr=new list<String>();
    Dom.Document docx = new Dom.Document();
        docx.load(str);
        dom.XmlNode xroot = docx.getrootelement() ;
        
        dom.XmlNode [] xrec = xroot.getchildelements() ; //Get all Record Elements
        system.debug('???????'+xrec);
        for(Dom.XMLNode child : xrec) //Loop Through Records
        {
            for(Dom.XMLNode child2:child.getchildren())
            {
                for(Dom.XMLNode child3:child2.getchildren())
                {
                system.debug(child3.gettext());
                }
            }
        }
    }
}     
     

All Answers

king s 8king s 8
This XML using  try this


public class parse{
    public void call(){
    String str=+'<?xml version="1.0" encoding="UTF-8"?>'
    +'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">'
    +'<apiVersion>27.0</apiVersion>'
    +'</ApexClass>';

    list<string> listr=new list<String>();
    Dom.Document docx = new Dom.Document();
        docx.load(str);
        dom.XmlNode xroot = docx.getrootelement() ;
        
        dom.XmlNode [] xrec = xroot.getchildelements() ; //Get all Record Elements
        system.debug('???????'+xrec);
        for(Dom.XMLNode child : xrec) //Loop Through Records
        {
            for(Dom.XMLNode child2:child.getchildren())
            {
                for(Dom.XMLNode child3:child2.getchildren())
                {
                system.debug(child3.gettext());
                }
            }
        }
    }
}     
     
This was selected as the best answer
Ashmi PatelAshmi Patel
bt i want to use this xml in this class...need help
king s 8king s 8
Hi Ashmi,
 use this methods inside the apex class
parse var=new parse();
var.call();

Regards
kullai