matlab.io.xml.dom.WriterConfiguration Class
Namespace: matlab.io.xml.dom
Description
Use properties of a matlab.io.xml.dom.WriterConfiguration
object to specify
options for an XML DOM writer represented as a matlab.io.xml.dom.DOMWriter
object. A WriterConfiguration
object is
created when you create a matlab.io.xml.dom.DOMWriter
object. Use the Configuration
property of the DOMWriter
object to access the
WriterConfiguration
object.
The matlab.io.xml.dom.WriterConfiguration
class is a handle
class.
Class Attributes
HandleCompatible | true |
ConstructOnLoad | true |
For information on class attributes, see Class Attributes.
Properties
FormatPrettyPrint
— Whether to pretty-print the output XML markup
false
(default) | true
Whether to pretty-print the output XML markup, specified as true
or false
. If the value is true
, the writer formats
the output by adding whitespace to produce the output in an indented, human-readable
form.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
XMLDeclaration
— Whether to include an XML declaration in the output
true
(default) | false
Whether to include an XML declaration in the output, specified as
true
or false
. If the value is
true
, the writer includes an XML declaration in the output.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
DTD
— Whether to include a DTD in the output
true
(default) | false
Whether to include a Document Type Definition (DTD) in the output, specified as
true
or false
, if the value is
true
, and the DOM document contains a Document Type Declaration
(DTD), the writer includes the DTD in the XML file output.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
BOM
— Whether to include a BOM in the output
false
(default) | true
Whether to include a byte order mark (BOM) in the output. If the value is
true
, the writer includes a BOM at the beginning of the XML file
output stream.
The writer includes a BOM only if it is writing to a file and the output encoding is one of these encodings:
UTF-8
UTF-16
UTF-16LE
UTF-16BE
UCS-4
UCS-4LE
UCS-4BE
For UTF-16 and UCS-4 encodings, the endian mode of the host machine is used to determine the BOM.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
DiscardDefaultContent
— Whether to discard default content in output
true
(default) | false
Whether to discard default content in the output, specified as
true
or false
. If the value is
true
, the writer uses available information, such as an XML schema,
DTD, and the specified flag on Attr
nodes, to decide which attributes
and content to discard. If the value is false
, the writer keeps all
attributes and content.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
SplitCDATASections
— Whether to split CDATA sections
true
(default) | false
Whether to split CDATA sections, specified as true
or
false
. If the value is true
, the writer splits
CDATA sections that contain the CDATA section termination marker
']]>'
or unrepresentable characters in the output encoding. If
the value is false
, the writer throws an error if a CDATA section
contains a CDATA section termination marker ']]>'
or an
unrepresentable character.
Attributes:
GetAccess | public |
SetAccess | public |
NonCopyable | true |
Examples
Format XML Output
Write an XML document to a file and format the XML output so that it is indented and readable.
Create an XML document as a matlab.io.xml.dom.Document
object.
import matlab.io.xml.dom.* docNode = Document("root_element"); docRootNode = getDocumentElement(docNode); weekdays = ["Mon" "Tue" "Wed" "Thu" "Fri"]; weekdaysElement = createElement(docNode,"weekdays"); for i=1:5 dayElement = createElement(docNode,"day"); appendChild(dayElement,createTextNode(docNode,weekdays(i))); appendChild(weekdaysElement,dayElement); end appendChild(docRootNode,weekdaysElement);
Create a writer to serialize the XML document.
xmlFileName = "weekdays.xml";
writer = matlab.io.xml.dom.DOMWriter;
Specify pretty-print formatting.
writer.Configuration.FormatPrettyPrint = true; writeToFile(writer,docNode,xmlFileName);
View the formatted file.
type(xmlFileName);
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> <root_element> <weekdays> <day>Mon</day> <day>Tue</day> <day>Wed</day> <day>Thu</day> <day>Fri</day> </weekdays> </root_element>
Version History
Introduced in R2021a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)