Skip to content

Function: serializeXml() ​

ts
function serializeXml(xml): string;

Defined in: xml/src/serializeXml.ts:14

Basic xml encoding utility. Encodes XML into a string.

Parameters ​

xml ​

XmlNode

The XML node to encode

Returns ​

string

The parsed XML

Example ​

ts
const xml = {
	nodeName: '#document',
	nodeValue: null,
	attributes: {},
	childNodes: [
		{
			nodeName: 'root',
			nodeValue: null,
			attributes: {},
			childNodes: [
				{
					nodeName: 'child',
					nodeValue: null,
					attributes: {
						hello: 'world',
					} as Record<string, string>,
					childNodes: [
						{
							nodeName: '#text',
							nodeValue: 'text',
							attributes: {},
							childNodes: [],
						},
					],
				},
				{
					nodeName: 'ns:tag',
					nodeValue: null,
					attributes: {},
					childNodes: [
						{
							nodeName: '#text',
							nodeValue: 'content',
							attributes: {},
							childNodes: [],
						},
					],
				},
			],
		},
	],
}

equal(
	serializeXml(xml),
	'<?xml version="1.0" encoding="UTF-8"?><root><child hello="world">text</child><ns:tag>content</ns:tag></root>',
)

A Streaming Video Technology Alliance project.