xmlprint

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

README

xmlprint

GoDoc Build Status

xmlprint pretty-prints XML documents.

It's intended to be both fast and configurable. With its default configuration, an XML document like this:

<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.BLUETOOTH" />
<application android:name=".Name" android:label="@string/app_name" android:icon="@mipmap/launcher" tools:ignore="UnusedAttribute">
<service android:name=".Service" android:enabled="true" android:exported="true">
</service>
<!-- This is a comment that
  spans multiple lines. -->
</application>
</manifest>

will be reformatted like this:

<?xml version="1.0" encoding="utf-8" ?>
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
  <uses-permission android:name="android.permission.BLUETOOTH" />
  <application
      android:icon="@mipmap/launcher"
      android:label="@string/app_name"
      android:name=".Name"
      tools:ignore="UnusedAttribute">
    <service
        android:enabled="true"
        android:exported="true"
        android:name=".Service" />
    <!-- This is a comment that
         spans multiple lines. -->
  </application>
</manifest>

Installation

Precompiled executables can be downloaded from the releases page.

To compile xmlprint from source and install it to $GOBIN (defaulting to $HOME/go/bin), install Go and run the following command:

go install ./cmd/xmlprint

Usage

Without any arguments, xmlprint reads XML input from stdin and writes formatted output to stdout before exiting with a 0 status code.

If xmlprint encounters an error, it prints it to stderr before exiting with a nonzero status code.

The -rewrite flag can be passed to rewrite the files or directories specified via positional arguments in-place.

The -check flag can be passed to check that the files or directories specified via positional arguments are already formatted correctly. If they aren't, the names of the improperly-formatted files will be printed to stdout and xmlprint will exit with a nonzero status code.

Command-line flags
Usage: xmlprint [flag]... <FILE/DIR>...
Pretty-prints XML files.

See https://codeberg.org/derat/xmlprint for details.

  -blank-lines string
    	Blank lines policy (collapse, preserve, remove) (default "collapse")
  -check
    	Check that files are properly formatted
  -closing-bracket-same-line
    	Print closing tag bracket on same line (default true)
  -comment-wrap-width int
    	Spaces when wrapping comments (default 5)
  -config string
    	Path to JSON configuration file
  -cpu-profile string
    	Destination path for CPU profile
  -dump-nodes
    	Dump nodes for debugging instead of pretty-printing
  -dump-tokens
    	Dump tokens for debugging instead of pretty-printing
  -extensions string
    	Comma-separated file extensions to format when directory is passed (default ".svg,.xml")
  -format-comments
    	Word-wrap comments
  -ignore-comment-directive string
    	String to place in comment to avoid reformatting next node (default "xmlprint-ignore")
  -ignore-xml-space
    	Ignore xml:space attributes instructing to preserve whitespace
  -indent-width int
    	Spaces for each indentation level (default 2)
  -iterations int
    	Number of times to format input for debugging (default 1)
  -jobs int
    	Maximum number of files to format at once (0 or negative for half of CPU count)
  -line-breaks string
    	How lines should be terminated (infer, lf, crlf) (default "infer")
  -memory-stats-interval duration
    	Interval for printing memory stats
  -non-ascii-whitespace string
    	How non-ASCII whitespace should be printed (preserve, escapeHex, escapeDecimal) (default "preserve")
  -pack-depth int
    	Maximum depth of element's children to pack on single line (default 2)
  -print-config
    	Print JSON config that would be used for file
  -print-width int
    	Desired maximum line length (default 80)
  -prioritize-attributes value
    	Comma-separated attribute names to prioritize when sorting
  -quotes string
    	How attribute values should be quoted (double, single, preferDouble, preferSingle) (default "double")
  -rewrite
    	Rewrite files in-place
  -rewrite-cdata
    	Rewrite "<![CDATA[...]]>" sections as escaped character data
  -self-closing
    	Use self-closing tags (default true)
  -self-closing-space
    	Print space before slash in self-closing tags (default true)
  -single-attribute-per-line
    	Print one attribute per line if tag doesn't fit on a single line (default true)
  -sort-attributes
    	Sort attributes by name (default true)
  -stdin-path string
    	Path to use for finding config when reading from stdin
  -tag-wrap-width int
    	Spaces when wrapping tags (default 4)
  -trailing-line-break
    	Print trailing line break at end of file (default true)
  -unbuffer
    	Write output immediately without buffering (slower)
  -use-tabs
    	Use tabs instead of spaces for indenting
  -version
    	Print the version and exit
  -whitespace string
    	Whitespace policy (trim, collapse, preserve) (default "trim")

Configuration

xmlprint loads configuration options from .xmlprint.json files. It looks for a configuration file in the XML file's directory, then the parent directory, and so on. As soon as it finds a file, it stops looking.

Command-line flags will override the corresponding configuration file options.

A configuration file contains a single JSON object with the following properties optionally set:


printWidth (int, default 80, flag -print-width)

Desired maximum line length.


indentWidth (int, default 2, flag -indent-width)

Number of spaces to use for each indentation level. If useTabs is true, this sets the number of characters that a tab will be considered to use.


tagWrapWidth (int, default 4, flag -tag-wrap-width)

Number of spaces to use when wrapping a tag. If useTabs is true, tagWrapWidth is divided by indentWidth to determine the number of tabs to use.


commentWrapWidth (int, default 5, flag -comment-wrap-width)

Number of spaces to use when wrapping a comment. If useTabs is true, commentWrapWidth is divided by indentWidth to determine the number of tabs to use.


useTabs (bool, default false, flag -use-tabs)

Indicates that a tab character should be used for indenting (rather than spaces).


lineBreaks (string, default infer, flag -line-breaks)

Specifies how lines should be terminated.

  • infer - Indicates that \r\n should be used if at least one \r\n sequence occurs near the beginning of the input file, with \n used otherwise.
  • lf - Indicates that lines should be terminated with \n.
  • crlf - Indicates that lines should be terminated with \r\n.

trailingLineBreak (bool, default true, flag -trailing-line-break)

Indicates that a trailing line break should be written at the end of the file.


packDepth (int, default 2, flag -pack-depth)

Specifies the maximum depth at which an element and its children will be printed on a single line if all will fit. With a packDepth of 2, <a><b><c/></b></a> (depth 2) would be printed on a single line but <a><b><c>foo</c></b></a> (depth 3) would not. A negative value specifies no limit and 0 specifies that elements should not be packed.


selfClosing (bool, default true, flag -self-closing)

Indicates that self-closing tags should be printed, e.g. <element />. Otherwise, they're written as separate tags, e.g. <element></element>.


selfClosingSpace (bool, default true, flag -self-closing-space)

Indicates that a space should be placed before the slash at the end of a self-closing tag, e.g. <element /> rather than <element/>.


closingBracketSameLine (bool, default true, flag -closing-bracket-same-line)

Indicates that a multiline tag's closing bracket should be printed on the same line as the final attribute. Otherwise, it's printed on a new line at the same indentation level as the opening bracket.


whitespace (string, default trim, flag -whitespace)

Specifies the extent to which whitespace in character data should be preserved.

  • trim - Attempts to intelligently handle whitespace in character data:

    • Data consisting only of newlines and other whitespace will be replaced with zero or more blank lines per blankLinePolicy.
    • Data containing at least one non-whitespace character is trimmed to remove leading and trailing whitespace on each line, but all other internal whitespace is preserved.
  • collapse - Is like trim but additionally replaces sequences of multiple whitespace characters with single spaces and wraps text after splitting it into words.

  • preserve - Preserves all whitespace within elements containing non-whitespace character data.

    As an example, given:

    <element>
        text 1
       <child>text 2</child>
     </element>
    

    the \n text 1\n and \n character data will be preserved, with no additional whitespace inserted.

    Otherwise, it acts like trim.

    Note that this policy can be substantially slower and use much more memory than other policies when processing large files, since earlier character data often cannot be processed until later character data has been seen.


ignoreXMLSpace (bool, default false, flag -ignore-xml-space)

Indicates that xml:space attributes should be ignored. If false, xml:space attributes with a value of preserve indicate that whitespace should be preserved within all inner character data.


blankLines (string, default collapse, flag -blank-lines)

Determines how blank lines in character data will be handled.

  • collapse - Indicates that one or more blank lines will be collapsed to a single blank line.
  • preserve - Indicates that all blank lines should be preserved.
  • remove - Indicates that all blank lines will be removed.

nonASCIIWhitespace (string, default preserve, flag -non-ascii-whitespace)

Specifies how non-ASCII whitespace should be printed.

  • preserve - Indicates that non-ASCII whitespace should be printed unchanged.
  • escapeHex - Indicates that non-ASCII whitespace should be printed as hexadecimal numeric character entities, e.g. +U+00A0 becomes &#xA0;.
  • escapeDecimal - Indicates that non-ASCII whitespace should be printed as decimal numeric character entities, e.g. +U+00A0 becomes &#160;.

rewriteCDATA (bool, default false, flag -rewrite-cdata)

Indicates that <![CDATA[...]]> sections should be rewritten as escaped character data. Otherwise, they are preserved (usually: large CDATA sections may be rewritten even when this is false, with large currently defined as approximately 8 KiB).


formatComments (bool, default false, flag -format-comments)

Indicates that comments should be word-wrapped. Otherwise, the original line breaks are preserved.

Note that even with a false value, comment lines are still trimmed and indented. To leave a comment completely unmodified (e.g. because it contains multiline ASCII art), add an ignore directive immediately before it (see ignoreCommentDirective).


singleAttributePerLine (bool, default true, flag -single-attribute-per-line)

Indicates that each attribute will be printed on its own line if the entire tag doesn't fit on a single line. Otherwise, multiple attributes may be printed on a single line if they fit.


quotes (string, default double, flag -quotes)

Describes how attribute values should be quoted.

  • double - Indicates that double quotes should always be used.
  • single - Indicates that single quotes should always be used.
  • preferDouble - Indicates that double quotes should be used unless the value contains one or more double quotes and zero single quotes.
  • preferSingle - Indicates that single quotes should be used unless the value contains one or more single quotes and zero double quotes.

sortAttributes (bool, default true, flag -sort-attributes)

Describes whether a tag's attributes should be sorted lexicographically by name, with xmlns attributes prioritized. If false, the original attribute order is preserved.


prioritizeAttributes (string array, flag -prioritize-attributes)

Contains ordered names of attributes to prioritize when sortAttributes is true. Names can be prefixed or unprefixed names (e.g. ns:attr or attr) or namespaces (to prioritize all attributes in that namespace).


ignoreCommentDirective (string, default xmlprint-ignore, flag -ignore-comment-directive)

Specifies a string that can be placed in a comment (e.g. xmlprint-ignore) to indicate that the original formatting of the next node should be preserved. -start and -end (e.g. xmlprint-ignore-start and xmlprint-ignore-end) can be appended to preserve all formatting between the two comments.


ignore (bool, default false)

Indicates that the file should not be formatted. This is intended to be set in an override, not at the top level of a configuration.


overrides (object array)

Contains additional configuration to apply to specific files.

files (string or string array)

Glob or array of globs matching XML files whose configuration should be overriden. The glob syntax at https://pkg.go.dev/path/filepath#Match is used. Globs are interpreted relative to the configuration file's directory. Globs can also match one of the XML file's ancestor directories. If the glob doesn't contain a slash, it will additionally be tested against the base filename (e.g. *bar.xml will match /blah/foobar.xml).

options (object)

Config struct.


Notes

Architecture

The xmlprint executable's main function is defined in cmd/xmlprint/main.go. It determines which files need to be formatted and then loads configurations (merging config files and command-line flags) and calls the Print function for each. Multiple files may be formatted concurrently, depending on value of the -jobs flag.

The Print function starts a goroutine that calls readStream, which uses reader to write node objects to a channel.

Each node represents a self-contained piece of the XML document (a start or end tag, character data, comment, etc.) to print. A node may contain atoms, each of which is an indivisible piece of text (e.g. <name at the beginning of a start tag). atoms may contain additional flags specifying how they should be printed (see the atomFlag type).

The Print function uses printer to consume nodes from the channel. printer writes each atom to the output io.Writer, using the atom's flags plus its own knowledge of the current line width and whether it's in an element to wrap and indent lines appropriately.

HTML

Modern HTML typically isn't valid XML, but XHTML is. HTML files often include other languages like JavaScript or CSS that should be formatted differently. xmlprint only knows how to format XML (and lacks HTML-specific heuristics for determining whitespace significance). If you need to format HTML, you may want to try using markup_fmt (perhaps in conjunction with dprint).

SVG

SVG documents can also contain CSS embedded in <style> elements. If you need to format CSS within SVG, consider using markup_fmt (mentioned above) or prettier's plugin-xml plugin instead.

Whitespace

Whitespace in XML documents is a complicated topic. Whitespace between element attributes or before a closing bracket can be freely modified without changing downstream applications' interpretation of the document, but whitespace in character data between tags may or may not be significant -- it's impossible to know without looking at the DTD. Even when there's a specification, applications sometimes don't agree about how whitespace should be handled.

When reformatting XML, it's possible to use heuristics to guess whether whitespace is significant in a particular context.

This page provides a simple approach for determining whitespace significance: if two tags are separated by character data containing only whitespace (or aren't separated by any character data), whitespace is insignificant; if the character data contains non-whitespace characters, the whitespace is significant.

Another approach might involve checking for the presence of mixed content: if an element contains any non-whitespace character data child nodes, then all of its character data should be printed without any modification.

The <oXygen/> XML Editor uses a complicated approach for inferring whitespace significance.

Some heuristics require looking ahead at upcoming tokens. Imagine the following input:

<root>
  <bold>Th</bold><italic>at's</italic> what I'm talking about.
</root>

Tokenization yields the following tags and character data:

  • <root>
  • "\n "
  • <bold>
  • Th
  • </bold>
  • <italic>
  • "at's"
  • </italic>
  • " what I'm talking about.\n"
  • </root>

At the point when <italic> is encountered, it's hard to guess whether whitespace under <root> is significant or not. If it isn't significant, printing the children in this style might be reasonable:

<root>
  <bold>Th</bold>
  <italic>at's</italic>
  ...

It's only after seeing non-whitespace characters in " what I'm talking about.\n" that we can guess that whitespace is significant, and that the <bold> and <italic> elements should be siblings and that the space at the beginning of the final character data node should be preserved.

Documentation

Overview

Package xmlprint pretty-prints XML data.

Index

Constants

This section is empty.

Variables

These shouldn't be reordered, as their index positions are used by checked-in fuzz inputs.

These shouldn't be reordered, as their index positions are used by checked-in fuzz inputs.

Functions

func Print

func Print(r io.Reader, w io.Writer, cfg *Config) error

Print reads an XML document from r and pretty-prints it to w.

Types

type BlankLinesPolicy

type BlankLinesPolicy string

BlankLinesPolicy specifies how newlines in character data are handled.

const (
	// CollapseBlankLines indicates that one or more blank lines will be collapsed to a single blank line.
	CollapseBlankLines BlankLinesPolicy = "collapse"
	// PreserveBlankLines indicates that all blank lines should be preserved.
	PreserveBlankLines BlankLinesPolicy = "preserve"
	// RemoveBlankLines indicates that all blank lines will be removed.
	RemoveBlankLines BlankLinesPolicy = "remove"
)

type Config

type Config struct {
	// PrintWidth is the desired maximum line length.
	PrintWidth int `json:"printWidth"`
	// IndentWidth is the number of spaces to use for each indentation level.
	// If UseTabs is true, this sets the number of characters that a tab will be considered to use.
	IndentWidth int `json:"indentWidth"`
	// TagWrapWidth is the number of spaces to use when wrapping a tag.
	// If UseTabs is true, TagWrapWidth is divided by IndentWidth to determine the number of tabs to use.
	TagWrapWidth int `json:"tagWrapWidth"`
	// CommentWrapWidth is the number of spaces to use when wrapping a comment.
	// If UseTabs is true, CommentWrapWidth is divided by IndentWidth to determine the number of
	// tabs to use.
	CommentWrapWidth int `json:"commentWrapWidth"`
	// UseTabs indicates that a tab character should be used for indenting (rather than spaces).
	UseTabs bool `json:"useTabs"`
	// LineBreaks specifies how lines should be terminated.
	LineBreaks LineBreaksPolicy `json:"lineBreaks"`
	// TrailingLineBreak indicates that a trailing line break should be written at the end of the
	// file.
	TrailingLineBreak bool `json:"trailingLineBreak"`

	// PackDepth specifies the maximum depth at which an element and its children will be printed on
	// a single line if all will fit. With a PackDepth of 2, "<a><b><c/></b></a>" (depth 2) would be
	// printed on a single line but "<a><b><c>foo</c></b></a>" (depth 3) would not. A negative value
	// specifies no limit and 0 specifies that elements should not be packed.
	PackDepth int `json:"packDepth"`
	// SelfClosing indicates that self-closing tags should be printed, e.g. "<element />".
	// Otherwise, they're written as separate tags, e.g. "<element></element>".
	SelfClosing bool `json:"selfClosing"`
	// SelfClosingSpace indicates that a space should be placed before the slash at the end of a
	// self-closing tag, e.g. "<element />" rather than "<element/>".
	SelfClosingSpace bool `json:"selfClosingSpace"`
	// ClosingBracketSameLine indicates that a multiline tag's closing bracket should be printed on
	// the same line as the final attribute. Otherwise, it's printed on a new line at the same
	// indentation level as the opening bracket.
	ClosingBracketSameLine bool `json:"closingBracketSameLine"`

	// Whitespace specifies the extent to which whitespace in character data should be preserved.
	Whitespace WhitespacePolicy `json:"whitespace"`
	// IgnoreXMLSpace indicates that "xml:space" attributes should be ignored.
	// If false, "xml:space" attributes with a value of "preserve" indicate that whitespace
	// should be preserved within all inner character data.
	IgnoreXMLSpace bool `json:"ignoreXMLSpace"`
	// BlankLines determines how blank lines in character data will be handled.
	BlankLines BlankLinesPolicy `json:"blankLines"`
	// NonASCIIWhitespace specifies how non-ASCII whitespace should be printed.
	NonASCIIWhitespace NonASCIIWhitespacePolicy `json:"nonASCIIWhitespace"`
	// RewriteCDATA indicates that "<![CDATA[...]]>" sections should be rewritten as escaped
	// character data. Otherwise, they are preserved (usually: large CDATA sections may be rewritten
	// even when this is false, with "large" currently defined as approximately 8 KiB).
	RewriteCDATA bool `json:"rewriteCDATA"`
	// FormatComments indicates that comments should be word-wrapped.
	// Otherwise, the original line breaks are preserved.
	//
	// Note that even with a false value, comment lines are still trimmed and indented.
	// To leave a comment completely unmodified (e.g. because it contains multiline ASCII art),
	// add an ignore directive immediately before it (see IgnoreCommentDirective).
	FormatComments bool `json:"formatComments"`

	// SingleAttributePerLine indicates that each attribute will be printed on its own line if the
	// entire tag doesn't fit on a single line. Otherwise, multiple attributes may be printed on a
	// single line if they fit.
	SingleAttributePerLine bool `json:"singleAttributePerLine"`
	// Quotes describes how attribute values should be quoted.
	Quotes QuotesPolicy `json:"quotes"`
	// SortAttributes describes whether a tag's attributes should be sorted lexicographically by
	// name, with "xmlns" attributes prioritized. If false, the original attribute order is preserved.
	SortAttributes bool `json:"sortAttributes"`
	// PrioritizeAttributes contains ordered names of attributes to prioritize when SortAttributes
	// is true. Names can be prefixed or unprefixed names (e.g. "ns:attr" or "attr") or namespaces
	// (to prioritize all attributes in that namespace).
	PrioritizeAttributes []string `json:"prioritizeAttributes"`

	// IgnoreCommentDirective specifies a string that can be placed in a comment (e.g. "xmlprint-ignore")
	// to indicate that the original formatting of the next node should be preserved.
	// "-start" and "-end" (e.g. "xmlprint-ignore-start" and "xmlprint-ignore-end") can be appended to
	// preserve all formatting between the two comments.
	IgnoreCommentDirective string `json:"ignoreCommentDirective"`

	// Ignore indicates that the file should not be formatted.
	// This is intended to be set in an override, not at the top level of a configuration.
	Ignore bool `json:"ignore"`

	// Overrides contains additional configuration to apply to specific files.
	Overrides []struct {
		// Files is a glob or array of globs matching XML files whose configuration should be
		// overriden. The glob syntax at https://pkg.go.dev/path/filepath#Match is used.
		// Globs are interpreted relative to the configuration file's directory.
		// Globs can also match one of the XML file's ancestor directories.
		// If the glob doesn't contain a slash, it will additionally be tested against the
		// base filename (e.g. "*bar.xml" will match "/blah/foobar.xml").
		Files stringOrArray `json:"files"`
		// Options is a Config struct.
		Options json.RawMessage `json:"options"`
	} `json:"overrides"`

	// DebugChecks enables (possibly-slow) runtime assertions.
	DebugChecks bool `json:"-"`
	// DumpNodes indicates that nodes should be dumped instead of pretty-printing the XML data.
	DumpNodes bool `json:"-"`
	// DumpTokens indicates that the raw tokens returned by the decoder should be dumped instead
	// of pretty-printing the XML data.
	DumpTokens bool `json:"-"`
	// Iterations indicates that the number of times that the input should be formatted.
	// It's useful for debugging unstable output.
	Iterations int `json:"-"`
	// contains filtered or unexported fields
}

Config specifies how XML data should be pretty-printed.

Names and values are chosen for consistency with https://github.com/g-plane/markup_fmt (https://markup-fmt.netlify.app/config/) and https://github.com/prettier/plugin-xml when there's no compelling reason to be different.

This struct should not be mutated after it has been initialized as it caches values. It is not safe to be used concurrently from multiple goroutines, and CloneWithoutOverrides should be used to make copies (and must be updated if new slice/map/etc. fields are added).

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config initialized to default values.

func (*Config) Check

func (cfg *Config) Check() error

Check performs basic validation of cfg.

func (*Config) CloneWithoutOverrides

func (cfg *Config) CloneWithoutOverrides() *Config

Clone returns a deep copy of cfg. The Overrides field and various cached fields are cleared.

type InputError

type InputError struct {
	Err    error
	Token  xml.Token
	Line   int
	Column int
	Offset int64
}

InputError wraps an error that occurred in the input and includes information about where it occurred.

func (InputError) Error

func (ie InputError) Error() string

func (InputError) Unwrap

func (ie InputError) Unwrap() error

type LineBreaksPolicy

type LineBreaksPolicy string

LineBreaksPolicy specifies how lines should be terminated.

const (
	// InferLineBreaks indicates that "\r\n" should be used if at least one "\r\n"
	// sequence occurs near the beginning of the input file, with "\n" used
	// otherwise.
	InferLineBreaks LineBreaksPolicy = "infer"
	// LFLineBreaks indicates that lines should be terminated with "\n".
	LFLineBreaks LineBreaksPolicy = "lf"
	// CRLFLineBreaks indicates that lines should be terminated with "\r\n".
	CRLFLineBreaks LineBreaksPolicy = "crlf"
)

type NonASCIIWhitespacePolicy

type NonASCIIWhitespacePolicy string

NonASCIIWhitespacePolicy indicates how non-ASCII whitespace should be printed within character data.

const (
	// PreserveNonASCIIWhitespace indicates that non-ASCII whitespace should be printed unchanged.
	PreserveNonASCIIWhitespace NonASCIIWhitespacePolicy = "preserve"
	// EscapeNonASCIIWhitespaceHex indicates that non-ASCII whitespace should be printed as
	// hexadecimal numeric character entities, e.g. +U+00A0 becomes "&#xA0;".
	EscapeNonASCIIWhitespaceHex NonASCIIWhitespacePolicy = "escapeHex"
	// EscapeNonASCIIWhitespaceDecimal indicates that non-ASCII whitespace should be printed as
	// decimal numeric character entities, e.g. +U+00A0 becomes "&#160;".
	EscapeNonASCIIWhitespaceDecimal NonASCIIWhitespacePolicy = "escapeDecimal"
)

type QuotesPolicy

type QuotesPolicy string

QuotesPolicy specifies how attribute values are quoted.

const (
	// DoubleQuotes indicates that double quotes should always be used.
	DoubleQuotes QuotesPolicy = "double"
	// SingleQuotes indicates that single quotes should always be used.
	SingleQuotes QuotesPolicy = "single"
	// PreferDoubleQuotes indicates that double quotes should be used unless the value
	// contains one or more double quotes and zero single quotes.
	PreferDoubleQuotes QuotesPolicy = "preferDouble"
	// PreferSingleQuotes indicates that single quotes should be used unless the value
	// contains one or more single quotes and zero double quotes.
	PreferSingleQuotes QuotesPolicy = "preferSingle"
)

type WhitespacePolicy

type WhitespacePolicy string

WhitespacePolicy specifies how whitespace in character data is handled.

const (
	// TrimWhitespace attempts to intelligently handle whitespace in character data:
	//  - Data consisting only of newlines and other whitespace will be replaced with
	//    zero or more blank lines per BlankLinePolicy.
	//  - Data containing at least one non-whitespace character is trimmed to remove leading
	//    and trailing whitespace on each line, but all other internal whitespace is preserved.
	TrimWhitespace WhitespacePolicy = "trim"
	// CollapseWhitespace is like "trim" but additionally replaces sequences of
	// multiple whitespace characters with single spaces and wraps text after splitting it
	// into words.
	CollapseWhitespace WhitespacePolicy = "collapse"
	// PreserveWhitespace preserves all whitespace within elements containing non-whitespace
	// character data.
	//
	// As an example, given:
	//  <element>
	//      text 1
	//     <child>text 2</child>
	//   </element>
	// the "\n    text 1\n   " and "\n " character data will be preserved, with no
	// additional whitespace inserted.
	//
	// Otherwise, it acts like "trim".
	//
	// Note that this policy can be substantially slower and use much more memory than other
	// policies when processing large files, since earlier character data often cannot be
	// processed until later character data has been seen.
	PreserveWhitespace WhitespacePolicy = "preserve"
)

Directories

Path Synopsis
cmd
xmlprint command
tools
fuzz command
readme command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL