Zum Hauptinhalt springen

XmlSerializerResult

Class returned by XmlSerializer.serialize.

warnung

An instance of this class is returned as the result of the serialize function in the XmlSerializer class.
In most cases this should also be enough 😉.

Constructors

Constructor

new XmlSerializerResult(document, parser?): XmlSerializerResult

new XmlSerializerResult(
document: DOMDocument,
parser?: DOMParser
): XmlSerializerResult

Example

const { XmlSerializer } = require("ou.sp.XmlSerializer");
const result = new XmlSerializerResult(document)

Parameters

document

DOMDocument

The DOMDocument

parser?

DOMParser

Class to be used for parsing the DOM (default otris DOMParser)

Returns

XmlSerializerResult

Methods

getRootElement()

getRootElement(): DOMElement

Returns the current Root Element.

getRootElement(): DOMElement

Returns

DOMElement


getDocument()

getDocument(): DOMDocument

Returns the current DOM document.

getDocument(): DOMDocument

Returns

DOMDocument


save()

save(path?, encoding?, prettyPrint?): string

Saves the current document by the given path.

save(path: string = "", encoding: SerializableEncodings = "UTF-8", prettyPrint: boolean = true): boolean | string

Parameters

path?

string

Optional file path to save the XML. If no file path provided, this function will return the content of the XML.

encoding?

XmlSerializableEncodings

Encoding to use (default "UTF-8")

prettyPrint?

boolean

Should the XML be in a readable format with line breaks?

Returns

string


toString()

toString(): string

Returns the DOMDocument as XML-String.

toString(): string

Example

const { XmlSerializer } = require("ou.sp.XmlSerializer");
const result = new XmlSerializerResult(document);

// Result as XML-String
const xml = result.toString();

Result:

<root>
<node1>Test1</node1>
<node2>Test2</node2>
</root>

Returns

string