XmlStreamWriter Class
The XmlStreamWriter class provides methods for writing XML data.
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 (Streaming API for XML). StAX is an API to read and write XML documents, originating from the Java programming language community.
The XmlStreamWriter class in Apex is based on its counterpart in Java. See Java XMLStreamWriter class.
See Also
The following are constructors for XmlStreamWriter.
-
Creates a new instance of the
XmlStreamWriterclass.
Creates a new instance of the XmlStreamWriter class.
public XmlStreamWriter()
The following are methods for XmlStreamWriter. All are instance methods.
-
Closes this instance of an XmlStreamWriter and free any resources associated with it.
-
Returns the XML written by the XmlStreamWriter instance.
-
Binds the specified URI to the default namespace. This URI is bound in the scope of the current START_ELEMENT – END_ELEMENT pair.
-
writeAttribute(prefix, namespaceUri, localName, value)
Writes an attribute to the output stream.
-
Writes the specified CData to the output stream.
-
Writes the specified text to the output stream.
-
Writes the specified comment to the output stream.
-
writeDefaultNamespace(namespaceUri)
Writes the specified namespace to the output stream.
-
writeEmptyElement(prefix, localName, namespaceUri)
Writes an empty element tag to the output stream.
-
Closes any start tags and writes corresponding end tags to the output stream.
-
Writes an end tag to the output stream, relying on the internal state of the writer to determine the prefix and local name.
-
writeNamespace(prefix, namespaceUri)
Writes the specified namespace to the output stream.
-
writeProcessingInstruction(target, data)
Writes the specified processing instruction.
-
writeStartDocument(encoding, version)
Writes the XML Declaration using the specified XML encoding and version.
-
writeStartElement(prefix, localName, namespaceUri)
Writes the start tag specified by localName to the output stream.
Closes this instance of an XmlStreamWriter and free any resources associated with it.
public Void close()
Type: Void
Returns the XML written by the XmlStreamWriter instance.
public String getXmlString()
Type: String
Binds the specified URI to the default namespace. This URI is bound in the scope of the current START_ELEMENT – END_ELEMENT pair.
public Void setDefaultNamespace(String uri)
-
uri:
Type: String
Type: Void
Writes an attribute to the output stream.
public Void writeAttribute(String prefix, String namespaceUri, String localName, String value)
-
prefix:
Type: String
-
namespaceUri:
Type: String
-
localName:
Type: String
Specifies the name of the attribute.
-
value:
Type: String
Type: Void
Writes the specified CData to the output stream.
public Void writeCData(String data)
-
data:
Type: String
Type: Void
Writes the specified text to the output stream.
public Void writeCharacters(String text)
-
text:
Type: String
Type: Void
Writes the specified comment to the output stream.
public Void writeComment(String comment)
-
comment:
Type: String
Type: Void
Writes the specified namespace to the output stream.
public Void writeDefaultNamespace(String namespaceUri)
-
namespaceUri:
Type: String
Type: Void
Writes an empty element tag to the output stream.
public Void writeEmptyElement(String prefix, String localName, String namespaceUri)
-
prefix:
Type: String
-
localName:
Type: String
Specifies the name of the tag to be written.
-
namespaceUri:
Type: String
Type: Void
Closes any start tags and writes corresponding end tags to the output stream.
public Void writeEndDocument()
Type: Void
Writes an end tag to the output stream, relying on the internal state of the writer to determine the prefix and local name.
public Void writeEndElement()
Type: Void
Writes the specified namespace to the output stream.
public Void writeNamespace(String prefix, String namespaceUri)
Type: Void
Writes the specified processing instruction.
public Void writeProcessingInstruction(String target, String data)
Type: Void
Writes the XML Declaration using the specified XML encoding and version.
public Void writeStartDocument(String encoding, String version)
Type: Void
Writes the start tag specified by localName to the output stream.
public Void writeStartElement(String prefix, String localName, String namespaceUri)
Type: Void