Skip to content

format & preserveOrder in XMLBuilder result in values being indented in the own lines #398

@redneb

Description

@redneb
  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?

Description

When XMLBuilder is created with both the format and preserveOrder options enabled, the xml string that it produces has values on a separate line and indented. In addition, it adds a newline at the beginning of output.

Code

const XMLdata = `
	<car>
		<color>purple</color>
		<type>minivan</type>
		<registration>2020-02-03</registration>
		<capacity>7</capacity>
	</car>
`;
const parser = new XMLParser({preserveOrder: true});
const builder = new XMLBuilder({preserveOrder: true, format: true});
const output = builder.build(parser.parse(XMLdata));
console.log(output);

Output


<car>
  <color>
    purple
  </color>
  <type>
    minivan
  </type>
  <registration>
    2020-02-03
  </registration>
  <capacity>
    7
  </capacity>
</car>

expected data

<car>
  <color>purple</color>
  <type>minivan</type>
  <registration>2020-02-03</registration>
  <capacity>7</capacity>
</car>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions