Sample/Example XmlStreamWriter using Apex in Salesforce

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’, ‘[email protected]’ );
w.writeCharacters( ‘sample’ );
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
String payload = w.getXmlString();
system.debug( ‘Payload is ‘ + payload );
w.close();



Output:

Leave a Reply