What I have to do is to get all fields of an sObject and converting it into xml runtime. I have all the fields. And I get field name and field label in xml tag. What I want is field value instead of label. I search a lot but couldn't find any good help.Here is my code.
public class XmlBuilderC{
String strAcId = '001280000033UsO';
String objNameAccount = 'Account';
String strContactId = '00328000001iIvs';
String objNameContact = 'Contact';
String xml;
XmlStreamWriter w = new XmlStreamWriter();
sObject sObjectAccount = [select id, name from account where id=:strAcId];
SObject sObjectContact = [select id from contact where id=:strContactId];
public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
//sObject objsObjectAccount = objAccount;
public XmlBuilderC(){
printXml(objNameAccount);
printXml(objNameContact);
}
public void printXml(String sObjectName){
Map <String, Schema.SObjectField> fieldMap = schemaMap.get(sObjectName).getDescribe().fields.getMap();
w.writeStartDocument('utf-8','1.0');
w.writeStartDocument(null,'<soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">');
for(Schema.SObjectField sfield : fieldMap.Values())
{
schema.describefieldresult dfield = sfield.getDescribe();
System.debug('dfield.getLocalName(): '+dfield.getLocalName());
w.writeStartElement(null,sObjectName,null);
w.writeStartElement(sObjectName,dfield.getname(),sObjectName);
w.writeCharacters(dfield.getLabel()); //***Here.***
w.writeEndElement();
w.writeEndDocument();
}
System.debug('End of printXml()');
}
public String getXml(){
System.debug('inside getXml');
xml = w.getXmlString();
System.debug('xml: '+w.getXmlString());
w.close();
System.debug('XmlStreamWriter closed');
return xml;
}
}