# Setting Environment Attributes for XML in ECMAScript

When you are using ECMAScript to handle XML, you can tailor how the parser renders your output. In particular, there are three global attributes you may be interested in setting. To set these, simply type or paste them in at the top of your JSX file with the values you want.

## Global Environment Attributes

prettyIndent—Specifies the number of spaces each child of your XML will be indented when converting the value to a string. This includes when printing to the console, when calling toString or toXMLString.

Usage: XML.environment.@prettyIndent = 4;

Default: 2.

prettyPrint—Specifies whether the your XML should be arranged with indents and line breaks when converting the value to a string. This includes when printing to the console, when calling toString or toXMLString.

Usage: XML.environment.@prettyPrint = false;

Default: true.

ignoreWhitespace—Specifies whether whitespace characters at the beginning or end of any textnode should be ignored when the XML is being parsed by the script interpreter.

Usage: XML.environment.@ignoreWhitespace = false;

Default: true.

Whitespace is defined as:

- '\t' \u0009 HORIZONTAL TABULATION
- '\n' \u000A NEW LINE
- '\f' \u000C FORM FEED
- '\r' \u000D CARRIAGE RETURN
- ' ' \u0020 SPACE
- Any character who's ASCII value is less than or equal to 0x20 (including control characters)

ignoreComments—Specifies whether XML comments should be ignored when the XML is being parsed.

Usage: XML.environment.@ignoreComments = false;

Default: true.

ignoreProcessingInstructions—Specifies whether XML processing instructions should be ignored when the XML is being parsed.

Usage: XML.environment.@ignoreProcessingInstructions = false;

Default: true.

literalIsDocument—Specifies whether the variable to which XML is bound represents the XML document or the XML's root.

Usage: XML.environment.@literalIsDocument = true;

Default: false.

For example, consider the following assignment:

    var myXml = <name><first>Joe</first><last>Schmoe</last></name>;

With literalIsDocument set to true, code to retrieve the first name might look like this:

    var firstName = myXml.name.first;

With literalIsDocument set to false (the default), the code would look like this:

    var firstName = myXml.first;

Related Topics

None.