You can use the XmlStreamWriter class to programmatically construct an XML document, then use HTTP classes to send the document to an external server.
The XmlStreamWriter class is similar to the XMLStreamWriter utility class from StAX.
The XmlStreamWriter class in Apex is based on its counterpart in Java. See the Java XMLStreamWriter class.
The following are constructors for XmlStreamWriter.
The following are methods for XmlStreamWriter. All are instance methods.
public Void close()
Type: Void
public String getXmlString()
Type: String
public Void setDefaultNamespace(String uri)
Type: Void
public Void writeAttribute(String prefix, String namespaceUri, String localName, String value)
Type: Void
public Void writeCData(String data)
Type: Void
public Void writeCharacters(String text)
Type: Void
public Void writeComment(String comment)
Type: Void
public Void writeDefaultNamespace(String namespaceUri)
Type: Void
public Void writeEndDocument()
Type: Void
public Void writeEndElement()
Type: Void