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

When to use XMLStreamWriter vs XMLNode to generate XML documents for HTTP Requests

I am a bit new to working with XML, but need to design a process to generate a document from the Opportunity object to be used as the 'payload' of an HTTP Request.


Looking at the APEX XML Classes it seems like the XMLStreamWriter and the Document/XMLNode classes will both generate XML, but which is easier to use for creating a fairly complex document?


My application is to extract a load of fields from the Opportunity and related objects, then add the field values into an XML document for submitting a form to another site.


Again, I'm new to this so I am unsure of whether to just design a straight-forward, albeit long process of just generating the XML document one element at a time, every time, or if I can build a template that I can query and parse replacing the text values with field values. Ultimately I need to end up with an XML Document that can be read by the service we're using.


I've read through the APEX guide for information on the XML classes, and taken some online training to get up to speed with XML, or at least a little closer to speed. But I'm generally confused by the XML classes and when to use one or the other for this particular application.


Thanks for any help.