You need to sign in to do that
Don't have an account?

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>
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>
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
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());
}
}
}
}
}
use this methods inside the apex class
parse var=new parse();
var.call();
Regards
kullai