April 25, 2020

Sample/Example XmlStreamWriter using Apex in Salesforce

Sample Code:

XmlStreamWriter w = new XmlStreamWriter();
w.writeStartDocument( null, '1.0' );
w.writeStartElement( null, 'test', null );
w.writeStartElement( null, 'example', null );
w.writeAttribute( null, null, 'email', 'test123@xyz.com' );
w.writeCharacters( 'sample' );
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
String payload = w.getXmlString();
system.debug( 'Payload is ' + payload );
w.close();


Output:


No comments:

Post a Comment